-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path92.py
54 lines (48 loc) · 968 Bytes
/
92.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import itertools
def next_link(n):
t = 0
for s in str(n):
t += int(s)**2
return t
next_links = [0]*10000001
solution = 0
print next_links
for e,n in enumerate(next_links):
print e,n
if e > 0 and n == 0:
# for n in next_links:
i = e
chain = list()
while True:
print i
if i == 89:
print "we're 89, chain: ",chain
solution += 1
for l in chain:
l = "%03d" % l
print l
perms = list(itertools.combinations(str(l),len(str(len(next_links)))-1))
print perms
for p in perms:
s = ''
for q in p:
s += q
s = int(s)
next_links[s] = 89
break
elif i == 1:
for l in chain:
l = "%03d" % l
perms = list(itertools.permutations(str(l),len(str(len(next_links)))-1))
for p in perms:
s = ''
for q in p:
s += q
s = int(s)
# print s
next_links[s] = 1
break
else:
chain.append(i)
i = next_link(i)
print next_links,solution