-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26.py
More file actions
executable file
·34 lines (30 loc) · 879 Bytes
/
26.py
File metadata and controls
executable file
·34 lines (30 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import time
def repeater(d):
output = []
n = 1
firstzero = True
while True:
foo = divmod(n, d)
if foo[1] == 0:
return [] # if the remainder is zero, then this is a non-repeating fraction
if foo in output:
return output # if we've seen this remainder/divisor combo, then we're going to repeat
if foo[0] == 0:
if not firstzero:
output.append(foo)
firstzero = False
else:
output.append(foo)
n -= (foo[0] * d)
n *= 10
return foo
starttime = time.time()
highrepeat = 0
highnum = 0
for i in range(1, 1000):
bar = len(repeater(i))
if bar > highrepeat:
highrepeat = bar
highnum = i
print('1/', highnum, ' has ', highrepeat, ' repeating digits', sep='')
print('Time to solve:', time.time() - starttime)