Easy bruteforce solution

This commit is contained in:
2020-11-08 23:28:22 +01:00
parent 605831c4f5
commit 46a3f5ae4a

26
30/main.py Normal file
View File

@@ -0,0 +1,26 @@
# Digit fifth powers
# 1634, 8208 and 9474 are the only number that can be written as the sum of the fourth powers of their digits
# Find the sum of all the numbers that can be written as the sum of the fifth powers of their digits
# Through some googling, we found an upper bound of the result at 6*9^5 = 354294
# So, we can just bruteforce it, not that big of a search space
def intToList(n):
return [int(d) for d in str(n)]
def sumIntPowers(n, p=5):
return sum([d**p for d in intToList(n)])
def main():
print("Hello, this is Patrick")
result = 0
for n in range(10, 999999):
if n == sumIntPowers(n):
result += n
print(result)
if __name__ == "__main__":
main()