We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
str
1 parent b677a68 commit 078b2e9Copy full SHA for 078b2e9
project_euler/problem_034/sol1.py
@@ -8,7 +8,7 @@
8
9
from math import factorial
10
11
-DIGIT_FACTORIAL = {str(d): factorial(d) for d in range(10)}
+DIGIT_FACTORIAL = [factorial(d) for d in range(10)]
12
13
14
def sum_of_digit_factorial(n: int) -> int:
@@ -19,7 +19,11 @@ def sum_of_digit_factorial(n: int) -> int:
19
>>> sum_of_digit_factorial(0)
20
1
21
"""
22
- return sum(DIGIT_FACTORIAL[d] for d in str(n))
+ s = 0
23
+ while n != 0:
24
+ s += DIGIT_FACTORIAL[n % 10]
25
+ n //= 10
26
+ return s
27
28
29
def solution() -> int:
0 commit comments