summaryrefslogtreecommitdiff
path: root/Problem26.py
blob: 8c5716118412ab1167642cefdfe842b5fc602afe (plain)
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
from decimal import *
getcontext().prec = 30
def repeatingelement(n):
    power = reoccuringlength(n)
    return int(pow(10,power)/n)
def reoccuringlength(n):
    n = str(Decimal(1)/Decimal(n))[2:]
    vals = [0]
    maxlength,posy, posx = 0,0,0
    for x in range(0,int(len(n)/2)+1):
        for y in range(0,x):
            if n.count(n[y:x]) > 1 and (x-y) > maxlength:
                vals.append(n[y:x])
                maxlength = (x-y)
    return maxlength

maxrecurringcycle,maxval = 0,0 
for x in range(2,1000):
    if repeatingelement(x) > maxrecurringcycle: 
        maxrecurringcycle = repeatingelement(x)
        maxval = x
print(maxval)
print(repeatingelement(7))

#Answer is 983