-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem_34.py
More file actions
30 lines (25 loc) · 943 Bytes
/
Problem_34.py
File metadata and controls
30 lines (25 loc) · 943 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
from math import factorial
# Find a lower/upper limit where a intersection occurs between two increasing functions
def findIntersectionNatural(f, g, inf=1, sup=1000):
n=inf
while n<=sup:
f_greater_g = f(n)>g(n)
n += 1
# print(f"{f(n)} -- {g(n)} -- {f_greater_g}")
if f_greater_g!=(f(n)>g(n)):
break
if f(n)==g(n):
return (n, n)
else:
return (n-1, n)
def main():
n_dig = max(findIntersectionNatural(lambda n: factorial(9)*n, lambda n: 10**n))
max_range = max(factorial(9)*n_dig, 10**n_dig)
curious_numbers = []
for n in range(10,max_range):
if sum([factorial(int(i)) for i in str(n)]) == n:
print(f"{[factorial(int(i)) for i in str(n)]} -- {sum([factorial(int(i)) for i in str(n)])} -- {n}")
curious_numbers.append(n)
print(f"Sum of curious numbers: {sum(curious_numbers)}")
if __name__=='__main__':
main()