Reciprocal divisors
In [33]:
def one_per_x(n):
r, f, m = [], [], 1
while m not in f:
f.append(m)
m *= 10
r.append(int(m/n))
m %= n
return ''.join(str(i) for i in r[f.index(m):])
In [34]:
one_per_x(7)
Out[34]:
In [44]:
def max_range(f, t):
from operator import itemgetter
return max( ( (x, len(one_per_x(x))) for x in range(f, t) ), key=itemgetter(1))
In [45]:
max_range(2, 1000)
Out[45]:
In [46]:
%timeit max_range(2, 1000)
In [ ]: