-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
30 lines (24 loc) · 891 Bytes
/
Copy pathsolution.py
File metadata and controls
30 lines (24 loc) · 891 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
import json
import time
def factorial(n):
_factorial = 1
for i in range(n, 0, -1):
_factorial *= i
return _factorial
def digit_factorials(n):
for i in range(n):
if i in [1, 2]:
continue
digit_facts = sum(map(lambda x: factorial(int(x)), str(i)))
if digit_facts == i:
yield i
# no number above 2540160 (fac(9)*7) can be equal to sum of factorials of its digis
# since it is seven digit and it is the highest possible seven digit number we
# are able to get as sum of single digit factorials (9999999).
def solution() -> int:
return sum(digit_factorials(2540160))
cpu_s, wall_s = time.process_time(), time.time()
result = solution()
cpu_e, wall_e = time.process_time(), time.time()
cpu_time, wall_time = cpu_e - cpu_s, wall_e - wall_s
print(json.dumps({"solution": result, "cpu": cpu_time, "wall": wall_time}))