Hello EZ,
I just looked up on Project Euler again and chose a random problem page. The problem number 119 attracted my attention. I did solve it but not satisfied with the solution. To put it simple I just bruteforced it.
Here it is :-
The solution I got is correct but still would love to see some really clever solution. Most of PE problems cover some math concept. But Is there something that is clearly visible ?
Would love your feed back and some better solutions too.
EDIT: Forgot the code
Python Code
def digitsum(num):
return sum(map(int, num))
data = []
for base in range(7, 80):
for expo in range (2, 10):
temp = base ** expo
if digitsum(str(temp)) == base:
data.append(temp)
print("{0}^{1} = {2}".format(base, expo, temp))
print(sorted(data)[29])
EDIT:-
Python One Liner Code :-
sorted([ b**e for b in range(7, 80) for e in range(2, 10) if b == sum(map(int, str(b**e))) ])[29]