mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
Improve Project Euler problem 034 solution 1 (#5165)
This commit is contained in:
parent
ba71005484
commit
5f7bb3e9f7
|
@ -8,6 +8,8 @@ Note: As 1! = 1 and 2! = 2 are not sums they are not included.
|
|||
|
||||
from math import factorial
|
||||
|
||||
DIGIT_FACTORIAL = {str(d): factorial(d) for d in range(10)}
|
||||
|
||||
|
||||
def sum_of_digit_factorial(n: int) -> int:
|
||||
"""
|
||||
|
@ -17,7 +19,7 @@ def sum_of_digit_factorial(n: int) -> int:
|
|||
>>> sum_of_digit_factorial(0)
|
||||
1
|
||||
"""
|
||||
return sum(factorial(int(char)) for char in str(n))
|
||||
return sum(DIGIT_FACTORIAL[d] for d in str(n))
|
||||
|
||||
|
||||
def solution() -> int:
|
||||
|
|
Loading…
Reference in New Issue
Block a user