File tree Expand file tree Collapse file tree 4 files changed +25
-16
lines changed
Expand file tree Collapse file tree 4 files changed +25
-16
lines changed Original file line number Diff line number Diff line change 11"""
2+ Problem 20: https://projecteuler.net/problem=20
3+
24n! means n × (n − 1) × ... × 3 × 2 × 1
35
46For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
810"""
911
1012
11- def factorial (n ):
13+ def factorial (num : int ) -> int :
14+ """Find the factorial of a given number n"""
1215 fact = 1
13- for i in range (1 , n + 1 ):
16+ for i in range (1 , num + 1 ):
1417 fact *= i
1518 return fact
1619
1720
18- def split_and_add (number ) :
21+ def split_and_add (number : int ) -> int :
1922 """Split number digits and add them."""
2023 sum_of_digits = 0
2124 while number > 0 :
@@ -25,8 +28,8 @@ def split_and_add(number):
2528 return sum_of_digits
2629
2730
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
3033 >>> solution(100)
3134 648
3235 >>> solution(50)
@@ -42,8 +45,8 @@ def solution(n):
4245 >>> solution(1)
4346 1
4447 """
45- f = factorial (n )
46- result = split_and_add (f )
48+ nfact = factorial (num )
49+ result = split_and_add (nfact )
4750 return result
4851
4952
Original file line number Diff line number Diff line change 11"""
2+ Problem 20: https://projecteuler.net/problem=20
3+
24n! means n × (n − 1) × ... × 3 × 2 × 1
35
46For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
911from math import factorial
1012
1113
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
1416 >>> solution(100)
1517 648
1618 >>> solution(50)
@@ -26,7 +28,7 @@ def solution(n):
2628 >>> solution(1)
2729 1
2830 """
29- return sum ([int (x ) for x in str (factorial (n ))])
31+ return sum ([int (x ) for x in str (factorial (num ))])
3032
3133
3234if __name__ == "__main__" :
Original file line number Diff line number Diff line change 11"""
2+ Problem 20: https://projecteuler.net/problem=20
3+
24n! means n × (n − 1) × ... × 3 × 2 × 1
35
46For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
911from math import factorial
1012
1113
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
1416 >>> solution(1000)
1517 10539
1618 >>> solution(200)
@@ -32,7 +34,7 @@ def solution(n):
3234 >>> solution(0)
3335 1
3436 """
35- return sum (map (int , str (factorial (n ))))
37+ return sum (map (int , str (factorial (num ))))
3638
3739
3840if __name__ == "__main__" :
Original file line number Diff line number Diff line change 11"""
2+ Problem 20: https://projecteuler.net/problem=20
3+
24n! means n × (n − 1) × ... × 3 × 2 × 1
35
46For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
810"""
911
1012
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
1315 >>> solution(100)
1416 648
1517 >>> solution(50)
@@ -27,7 +29,7 @@ def solution(n):
2729 """
2830 fact = 1
2931 result = 0
30- for i in range (1 , n + 1 ):
32+ for i in range (1 , num + 1 ):
3133 fact *= i
3234
3335 for j in str (fact ):
You can’t perform that action at this time.
0 commit comments