-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path074.py
More file actions
38 lines (30 loc) · 744 Bytes
/
074.py
File metadata and controls
38 lines (30 loc) · 744 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
35
36
37
38
#!/usr/bin/python
#not really fast, but hey, it works!
def factorial(n):
if n==1:
return 1
return n*factorial(n-1)
factlist = [1] + [factorial(i) for i in range(1,10)] #list with factorials below 10
def digitfactorial(n):
tot = 0
for i in str(n):
tot += factlist[int(i)]
return tot
factlenlist = [0 for i in range(10**6)]
def factlength(n): #returns length of a chain
if factlenlist[n] > 0:
return factlenlist[n]
hadlist = [n]
for i in range(60):
new = digitfactorial(hadlist[i])
if new in hadlist:
for j in range(len(hadlist)):
if hadlist[j] < 10**6:
factlenlist[hadlist[j]] = i-j
return i+1
hadlist = hadlist + [new]
tot = 0
for i in range(10**6):
if factlength(i) == 60:
tot += 1
print tot