Digit power sum
Problem 119
The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.
We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.
You are given that a2 = 512 and a10 = 614656.
Find a30.
def run(limit=20):
# Finds all terms with <= 20 digits e.q. max_digits
max_val = 10**limit
found = []
for n in range(2, 9 * limit):
x = n
while x < max_val:
if sum(int(i) for i in str(x)) == n:
if x > 10:
found.append(x)
x *= n
found.sort()
return found[29]