From f4e606a6d7367b015eff488d5c6484f7063229f8 Mon Sep 17 00:00:00 2001 From: steven-y-e Date: Wed, 2 Aug 2023 12:33:45 -0400 Subject: [PATCH] feat(solution): problem #34 --- solutions/034/digitfactorials.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solutions/034/digitfactorials.py diff --git a/solutions/034/digitfactorials.py b/solutions/034/digitfactorials.py new file mode 100644 index 0000000..27aa186 --- /dev/null +++ b/solutions/034/digitfactorials.py @@ -0,0 +1,18 @@ +factorials = list(range(10)) +factorials[0] = 1 +for i in range(1, 10): + factorials[i] = factorials[i - 1] * i + +def sum_factorials(n): + sum = 0 + for i in list(str(n)): + sum += factorials[int(i)] + return sum + +sum_all_factorials = 0 + +for i in range(10,10000000): + if i == sum_factorials(i): + sum_all_factorials += i + +print(sum_all_factorials) \ No newline at end of file