File tree 4 files changed +25
-16
lines changed
4 files changed +25
-16
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
+ Problem 20: https://projecteuler.net/problem=20
3
+
2
4
n! means n × (n − 1) × ... × 3 × 2 × 1
3
5
4
6
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
8
10
"""
9
11
10
12
11
- def factorial (n ):
13
+ def factorial (num : int ) -> int :
14
+ """Find the factorial of a given number n"""
12
15
fact = 1
13
- for i in range (1 , n + 1 ):
16
+ for i in range (1 , num + 1 ):
14
17
fact *= i
15
18
return fact
16
19
17
20
18
- def split_and_add (number ) :
21
+ def split_and_add (number : int ) -> int :
19
22
"""Split number digits and add them."""
20
23
sum_of_digits = 0
21
24
while number > 0 :
@@ -25,8 +28,8 @@ def split_and_add(number):
25
28
return sum_of_digits
26
29
27
30
28
- def solution (n ) :
29
- """Returns the sum of the digits in the number 100!
31
+ def solution (num : int = 100 ) -> int :
32
+ """Returns the sum of the digits in the factorial of num
30
33
>>> solution(100)
31
34
648
32
35
>>> solution(50)
@@ -42,8 +45,8 @@ def solution(n):
42
45
>>> solution(1)
43
46
1
44
47
"""
45
- f = factorial (n )
46
- result = split_and_add (f )
48
+ nfact = factorial (num )
49
+ result = split_and_add (nfact )
47
50
return result
48
51
49
52
Original file line number Diff line number Diff line change 1
1
"""
2
+ Problem 20: https://projecteuler.net/problem=20
3
+
2
4
n! means n × (n − 1) × ... × 3 × 2 × 1
3
5
4
6
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
9
11
from math import factorial
10
12
11
13
12
- def solution (n ) :
13
- """Returns the sum of the digits in the number 100!
14
+ def solution (num : int = 100 ) -> int :
15
+ """Returns the sum of the digits in the factorial of num
14
16
>>> solution(100)
15
17
648
16
18
>>> solution(50)
@@ -26,7 +28,7 @@ def solution(n):
26
28
>>> solution(1)
27
29
1
28
30
"""
29
- return sum ([int (x ) for x in str (factorial (n ))])
31
+ return sum ([int (x ) for x in str (factorial (num ))])
30
32
31
33
32
34
if __name__ == "__main__" :
Original file line number Diff line number Diff line change 1
1
"""
2
+ Problem 20: https://projecteuler.net/problem=20
3
+
2
4
n! means n × (n − 1) × ... × 3 × 2 × 1
3
5
4
6
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
9
11
from math import factorial
10
12
11
13
12
- def solution (n ) :
13
- """Returns the sum of the digits in the number 100!
14
+ def solution (num : int = 100 ) -> int :
15
+ """Returns the sum of the digits in the factorial of num
14
16
>>> solution(1000)
15
17
10539
16
18
>>> solution(200)
@@ -32,7 +34,7 @@ def solution(n):
32
34
>>> solution(0)
33
35
1
34
36
"""
35
- return sum (map (int , str (factorial (n ))))
37
+ return sum (map (int , str (factorial (num ))))
36
38
37
39
38
40
if __name__ == "__main__" :
Original file line number Diff line number Diff line change 1
1
"""
2
+ Problem 20: https://projecteuler.net/problem=20
3
+
2
4
n! means n × (n − 1) × ... × 3 × 2 × 1
3
5
4
6
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
8
10
"""
9
11
10
12
11
- def solution (n ) :
12
- """Returns the sum of the digits in the number 100!
13
+ def solution (num : int = 100 ) -> int :
14
+ """Returns the sum of the digits in the factorial of num
13
15
>>> solution(100)
14
16
648
15
17
>>> solution(50)
@@ -27,7 +29,7 @@ def solution(n):
27
29
"""
28
30
fact = 1
29
31
result = 0
30
- for i in range (1 , n + 1 ):
32
+ for i in range (1 , num + 1 ):
31
33
fact *= i
32
34
33
35
for j in str (fact ):
You can’t perform that action at this time.
0 commit comments