Created
June 7, 2021 17:15
-
-
Save vernomcrp/db9fcabe20d298aaad4260b99b9b014d to your computer and use it in GitHub Desktop.
binary period
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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