Skip to content

Instantly share code, notes, and snippets.

@vernomcrp
Created June 7, 2021 17:15
Show Gist options
  • Select an option

  • Save vernomcrp/db9fcabe20d298aaad4260b99b9b014d to your computer and use it in GitHub Desktop.

Select an option

Save vernomcrp/db9fcabe20d298aaad4260b99b9b014d to your computer and use it in GitHub Desktop.
binary period
# https://stackoverflow.com/questions/57143272/fix-the-solution-of-binary-period
def solution(n):
d = [0] * 30
l = 0
while n > 0:
d[l] = n % 2
n //= 2
l += 1
for p in range(1, 1 + l//2): #here you put l//2
ok = True
print('p est ',p)
for i in range(l - p):
if d[i] != d[i + p]:
ok = False
break
if ok:
return
return -1 # do we need this ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment