File tree 1 file changed +8
-3
lines changed
project_euler/problem_034
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 8
8
9
9
from math import factorial
10
10
11
- DIGIT_FACTORIAL = { str ( d ): factorial (d ) for d in range (10 )}
11
+ DIGIT_FACTORIAL = [ factorial (d ) for d in range (10 )]
12
12
13
13
14
14
def sum_of_digit_factorial (n : int ) -> int :
@@ -19,7 +19,11 @@ def sum_of_digit_factorial(n: int) -> int:
19
19
>>> sum_of_digit_factorial(0)
20
20
1
21
21
"""
22
- return sum (DIGIT_FACTORIAL [d ] for d in str (n ))
22
+ s = 0
23
+ while n != 0 :
24
+ s += DIGIT_FACTORIAL [n % 10 ]
25
+ n //= 10
26
+ return s
23
27
24
28
25
29
def solution () -> int :
@@ -30,7 +34,8 @@ def solution() -> int:
30
34
>>> solution()
31
35
40730
32
36
"""
33
- limit = 7 * factorial (9 ) + 1
37
+ # limit = 7 * factorial(9) + 1
38
+ limit = 1_499_999
34
39
return sum (i for i in range (3 , limit ) if sum_of_digit_factorial (i ) == i )
35
40
36
41
You can’t perform that action at this time.
0 commit comments