Skip to content

Improve Project Euler problem 034 solution 1 #5165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion project_euler/problem_034/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from math import factorial

DIGIT_FACTORIAL = {str(d): factorial(d) for d in range(10)}


def sum_of_digit_factorial(n: int) -> int:
"""
Expand All @@ -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:
Expand Down