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)
| 54 | |
| 55 | |
| 56 | def 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 | |
| 73 | def chain_length(n: int, previous: set | None = None) -> int: |