27 lines
527 B
Python
27 lines
527 B
Python
from lib_misc import factorial
|
|
|
|
|
|
def is_curious(n):
|
|
s = sum([factorial(int(d)) for d in str(n)])
|
|
return n == s
|
|
|
|
|
|
def is_curious_faster(n):
|
|
""" Potentially faster solution. """
|
|
s = 0
|
|
for d in str(n):
|
|
s += factorial(int(d))
|
|
if s > n:
|
|
return False
|
|
return n == s
|
|
|
|
|
|
def euler_034():
|
|
return sum([n for n in range(3, 10**5) if is_curious(n)])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
assert(is_curious(145))
|
|
print("e034.py: {}".format(euler_034()))
|
|
assert(euler_034() == 40730)
|