projecteuler034 - digit factorials
"""
Scott Santarromana
projecteuler034 - digit factorials
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.
"""
from math import factorial
def init_fact_dict():
return {0:1,1:1,2:2,3:6,4:24,5:120,6:720,7:5040,8:40320,9:362880}
def sum_facts_of_digits(max):
facts = init_fact_dict()
for idx in range(max):
f2 = 0
for c in str(idx):
if f2 > idx:
break
f2 += facts[int(c)]
if idx == f2:
print idx
sum_facts_of_digits(9999999)