Digit factorials
Problem 34
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.
def run():
# factorials up to 0!, 1!, ... 9!
f = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
s = 0
for n in range(3, 100000):
if n == sum(f[int(d)] for d in str(n)):
s += n
return s