Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Add suggestions
Source Link
notjagan
  • 4.2k
  • 10
  • 27

Python 3, (削除) 68 (削除ここまで) 66(削除) 66 (削除ここまで) 60 bytes

-2 bytes thanks to Mr. Xcoder!

-4 bytes thanks to ovs!

-2 bytes thanks to Erik the Outgolfer!

lambda n:max((n>>i+8<<i)+(n&2**i-1)n%2**i|n>>i+8<<i for i in range(len(bin(n))-109))

Try it online! Try it online!

Python 3, (削除) 68 (削除ここまで) 66 bytes

-2 bytes thanks to Mr. Xcoder!

lambda n:max((n>>i+8<<i)+(n&2**i-1)for i in range(len(bin(n))-10))

Try it online!

Python 3, (削除) 68 (削除ここまで) (削除) 66 (削除ここまで) 60 bytes

-2 bytes thanks to Mr. Xcoder!

-4 bytes thanks to ovs!

-2 bytes thanks to Erik the Outgolfer!

lambda n:max(n%2**i|n>>i+8<<i for i in range(len(bin(n))-9))

Try it online!

Add suggestion
Source Link
notjagan
  • 4.2k
  • 10
  • 27

Python 3, 68(削除) 68 (削除ここまで) 66 bytes

-2 bytes thanks to Mr. Xcoder!

lambda n:max((n>>i+8<<i)+(n&2**i-1)for i in range(n.bit_lengthlen(bin(n))-810))

Try it online! Try it online!

Python 3, 68 bytes

lambda n:max((n>>i+8<<i)+(n&2**i-1)for i in range(n.bit_length()-8))

Try it online!

Python 3, (削除) 68 (削除ここまで) 66 bytes

-2 bytes thanks to Mr. Xcoder!

lambda n:max((n>>i+8<<i)+(n&2**i-1)for i in range(len(bin(n))-10))

Try it online!

Source Link
notjagan
  • 4.2k
  • 10
  • 27

Python 3, 68 bytes

lambda n:max((n>>i+8<<i)+(n&2**i-1)for i in range(n.bit_length()-8))

Try it online!

AltStyle によって変換されたページ (->オリジナル) /