Created
March 23, 2011 02:34
-
-
Save clementi/882513 to your computer and use it in GitHub Desktop.
Project Euler Problem #30 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 digital_power_sum(n_digits, p): | |
return sum(map(lambda x: x ** p, n_digits)) | |
def digital_power_sums(p): | |
for n in range(digital_power_sum(digits(999999), 5) + 1): | |
n_digits = digits(n) | |
if len(n_digits) > 1 and digital_power_sum(n_digits, 5) == n: | |
yield n | |
print sum(digital_power_sums(5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment