Restructure 5
This commit is contained in:
parent
7adc277e90
commit
c96de2bc6b
21
0005.py
21
0005.py
@ -4,11 +4,14 @@ import util
|
||||
|
||||
target = 232792560
|
||||
|
||||
def divisible(rng):
|
||||
def smallest_multiple(nbrs):
|
||||
factors = None
|
||||
|
||||
for num in rng:
|
||||
# get the prime factors of all nbrs, and keep the highest occurence of each unique prime factor
|
||||
# in each number
|
||||
for num in nbrs:
|
||||
nums = util.find_prime_factors(num)
|
||||
|
||||
count = Counter(nums)
|
||||
|
||||
if (factors == None):
|
||||
@ -17,17 +20,15 @@ def divisible(rng):
|
||||
for key, value in count.items():
|
||||
if (not factors[key] or value > factors[key]):
|
||||
factors[key] = value
|
||||
result = 1
|
||||
|
||||
return factors
|
||||
|
||||
|
||||
factors = divisible(range(1, 21))
|
||||
|
||||
result = 1
|
||||
|
||||
for key, value in factors.items():
|
||||
for key, value in factors.items():
|
||||
result *= key ** value
|
||||
|
||||
return result
|
||||
|
||||
result = smallest_multiple(range(1, 21))
|
||||
|
||||
print(result)
|
||||
print(result == target)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user