Problem 20 (and factorial util)
This commit is contained in:
parent
9a33095ecc
commit
40158db6a1
12
0020.py
Normal file
12
0020.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
from functools import reduce
|
||||||
|
|
||||||
|
import util
|
||||||
|
|
||||||
|
target = 648
|
||||||
|
|
||||||
|
result = util.factorial(100)
|
||||||
|
|
||||||
|
digits_sum = reduce(lambda x, y: x + y, map(lambda x: int(x), list(str(result))))
|
||||||
|
|
||||||
|
print(digits_sum)
|
||||||
|
print(digits_sum == target)
|
||||||
5
util.py
5
util.py
@ -1,3 +1,5 @@
|
|||||||
|
from functools import reduce
|
||||||
|
|
||||||
def find_largest_prime_factor(n):
|
def find_largest_prime_factor(n):
|
||||||
prime_factor = 1
|
prime_factor = 1
|
||||||
factors.append(prime_factor)
|
factors.append(prime_factor)
|
||||||
@ -34,3 +36,6 @@ def find_prime_factors(n):
|
|||||||
factors.append(n)
|
factors.append(n)
|
||||||
|
|
||||||
return factors
|
return factors
|
||||||
|
|
||||||
|
def factorial(n):
|
||||||
|
return reduce(lambda x, y: x * y, range(1, n + 1))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user