Skip to content

Instantly share code, notes, and snippets.

@clementi
Created March 23, 2011 02:34
Show Gist options
  • Save clementi/882513 to your computer and use it in GitHub Desktop.
Save clementi/882513 to your computer and use it in GitHub Desktop.
Project Euler Problem #30 Solution
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