Skip to content

Commit 5f7bb3e

Browse files
Improve Project Euler problem 034 solution 1 (TheAlgorithms#5165)
1 parent ba71005 commit 5f7bb3e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

project_euler/problem_034/sol1.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from math import factorial
1010

11+
DIGIT_FACTORIAL = {str(d): factorial(d) for d in range(10)}
12+
1113

1214
def sum_of_digit_factorial(n: int) -> int:
1315
"""
@@ -17,7 +19,7 @@ def sum_of_digit_factorial(n: int) -> int:
1719
>>> sum_of_digit_factorial(0)
1820
1
1921
"""
20-
return sum(factorial(int(char)) for char in str(n))
22+
return sum(DIGIT_FACTORIAL[d] for d in str(n))
2123

2224

2325
def solution() -> int:

0 commit comments

Comments
 (0)