-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem74.py
More file actions
38 lines (25 loc) · 784 Bytes
/
Problem74.py
File metadata and controls
38 lines (25 loc) · 784 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
from math import factorial
def Solve(length=60, limit=1_000_000):
def step(x):
return sum(factorial(int(d)) for d in str(x))
def chain_len(x, seen=None, cache={}):
if x in cache:
return cache[x]
else:
seen = seen or set()
if x in seen:
answer = 0
else:
seen.add(x)
next_x = step(x)
next_len = chain_len(next_x, seen)
answer = next_len + 1
cache[x] = answer
return answer
def seeds(length=60, limit=1_000_000):
for i in range(1, limit):
if chain_len(i) == length:
yield i
return len(list(seeds()))
if __name__ == '__main__':
print(Solve())