Created
March 23, 2011 03:37
-
-
Save clementi/882571 to your computer and use it in GitHub Desktop.
Project Euler Problem #34 Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def digits(n): | |
result = [] | |
while n > 0: | |
result = [n % 10] + result | |
n /= 10 | |
if not result: | |
return [0] | |
return result | |
def factorial(n): | |
return 1 if n == 0 else reduce(lambda x, y: x * y, range(1, n + 1)) | |
def digital_factorial_sum(n): | |
return sum(map(lambda d: factorial(d), digits(n))) | |
def digital_factorial_sums(): | |
for n in range(1, digital_factorial_sum(9999999) + 1): | |
if n >= 10 and digital_factorial_sum(n) == n: | |
yield n | |
print sum(digital_factorial_sums()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment