diff --git a/34/main.py b/34/main.py new file mode 100644 index 0000000..be61508 --- /dev/null +++ b/34/main.py @@ -0,0 +1,31 @@ +''' +145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. + +Find the sum of all numbers which are equal to the sum of the factorial of their digits. + +Note: As 1! = 1 and 2! = 2 are not sums they are not included. +''' + +import math + +def listify(i): + return [int(x) for x in str(i)] + +def check(i): + l = [math.factorial(x) for x in listify(i)] + return i == sum(l) + +def main(): + print("This is Patrick") + + res = 0 + + for i in range(1000000): + if check(i): + res += i + print(i) + + print(res - 3) + +if __name__ == "__main__": + main() \ No newline at end of file