DekGenius.com
Home
(current)
Dictionary
BOOKS
LYRICS
CHORD
SCRIPT & CODE EXAMPLE
Karaoke language
Search
Go
SCRIPT & CODE EXAMPLE
CODE EXAMPLE FOR PYTHON
A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.
def max_gap(N): xs = bin(N)[2:].strip('0').split('1') return max([len(x) for x in xs])
Source by stackoverflow.com #
PREVIOUS
NEXT
Tagged:
#A
#binary
#gap
#positive
#integer
#N
#maximal
#sequence
#consecutive
#zeros
#surrounded
#ends
#binary
#representation
ADD COMMENT
Topic
COMMENT
Name
9+6 =
Submit