diff --git a/30/main.py b/30/main.py new file mode 100644 index 0000000..da3c24c --- /dev/null +++ b/30/main.py @@ -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() \ No newline at end of file