Reciprocal cycles
First read the problem description.
def cycle_length(d):
= 1
n = []
numerators
while True:
*= 10
n try:
= numerators.index(n)
cycle_start return len(numerators[cycle_start:])
except ValueError:
numerators.append(n)= n % d
n if n == 0:
return 0
= 0
longest_length = None
longest_d
for d in range(2, 1000):
= cycle_length(d)
l if l > longest_length:
= l
longest_length = d longest_d
Source code of the solution(s):