-
Notifications
You must be signed in to change notification settings - Fork 0
/
pe34.py
32 lines (23 loc) · 820 Bytes
/
pe34.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
"""----------------------------------------------------------------------------
Project Euler
Gregory Gundersen
2013-02
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
Find the sum of all numbers which are equal to the sum of the factorial of
their digits.
Note: as 1! = 1 and 2! = 2 are not sums they are not included.
Solution:
The critical problem is finding an upper bound. This is the reasoning behind
my limit:
9! is the maximum value for any one digit
9! < 7 digits
9! * 7 is the upper bound
----------------------------------------------------------------------------"""
import gmath
def main():
limit = 7 * gmath.get_factorial(9)
result = 0
for n in range(3, limit):
if n == sum(gmath.get_factorial(int(i)) for i in str(n)):
result += n
return result