Created
April 25, 2020 19:43
-
-
Save tomfa/10db6f7f999c98cf7c1899675786286d to your computer and use it in GitHub Desktop.
This file contains 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
from decimal import * | |
getcontext().prec = 2000 | |
def find_recurring_length(divisor): | |
digits = (Decimal(1) / Decimal(divisor)).as_tuple().digits[:-1] | |
precision = getcontext().prec -1 | |
if len(digits) != precision: | |
return 0 | |
recurring = 0 | |
for i in range(0, 7): | |
l_digits = digits[i:] | |
l = len(l_digits) | |
for j in range(1, int(l / 2)): | |
multiplier = int(l/j) | |
if l_digits[:j] * (multiplier) == l_digits[:multiplier * j]: | |
return j | |
assert False, f'Could not find recurrence for {divisor}' | |
def findit(): | |
longest_reccuring = (0, 0) | |
for i in range(2, 1000): | |
_, length = longest_reccuring | |
ans = find_recurring_length(i) | |
if ans > length: | |
longest_reccuring = (i, ans) | |
print(f'{ans} > {length} for {i}') | |
def works(): | |
assert find_recurring_length(3) == 1, f'{3} != 1' | |
print(f'{(3)} works') | |
assert find_recurring_length(6) == 1, f'{6} != 1' | |
print(f'{(6)} works') | |
assert find_recurring_length(7) == 6, f'{7} != 6' | |
print(f'{(7)} works') | |
assert find_recurring_length(9) == 1, f'{9} != 1' | |
print(f'{(9)} works') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment