Skip to content

Instantly share code, notes, and snippets.

@grevych
Created September 17, 2020 01:30
Show Gist options
  • Save grevych/e63cc48dfe00fd038043c599b7b560fa to your computer and use it in GitHub Desktop.
Save grevych/e63cc48dfe00fd038043c599b7b560fa to your computer and use it in GitHub Desktop.

Revisions

  1. grevych created this gist Sep 17, 2020.
    21 changes: 21 additions & 0 deletions binary_substring.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    def solution(n):
    d = [0] * 30
    l = 0
    while (n > 0):
    d[l] = n % 2
    n //= 2
    l += 1
    for p in range(1, l - 1):
    ok = True
    print(d[:l-p])
    for i in range(l - p):
    print(i, p, d[:i + p + 1])
    if d[i] != d[i + p]:
    ok = False
    break
    if ok and l - p > p:
    return p
    return -1


    print(solution(955))