MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / sum_digit_factorials

Function sum_digit_factorials

project_euler/problem_074/sol1.py:56–70  ·  view source on GitHub ↗

Return the sum of the factorial of the digits of n. >>> sum_digit_factorials(145) 145 >>> sum_digit_factorials(45361) 871 >>> sum_digit_factorials(540) 145

(n: int)

Source from the content-addressed store, hash-verified

54
55
56def sum_digit_factorials(n: int) -> int:
57 """
58 Return the sum of the factorial of the digits of n.
59 >>> sum_digit_factorials(145)
60 145
61 >>> sum_digit_factorials(45361)
62 871
63 >>> sum_digit_factorials(540)
64 145
65 """
66 if n in CACHE_SUM_DIGIT_FACTORIALS:
67 return CACHE_SUM_DIGIT_FACTORIALS[n]
68 ret = sum(DIGIT_FACTORIALS[let] for let in str(n))
69 CACHE_SUM_DIGIT_FACTORIALS[n] = ret
70 return ret
71
72
73def chain_length(n: int, previous: set | None = None) -> int:

Callers 1

chain_lengthFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected