Restructure 5

This commit is contained in:
Linus Miller 2018-03-28 20:48:35 +02:00
parent 7adc277e90
commit c96de2bc6b

21
0005.py
View File

@ -4,11 +4,14 @@ import util
target = 232792560 target = 232792560
def divisible(rng): def smallest_multiple(nbrs):
factors = None 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) nums = util.find_prime_factors(num)
count = Counter(nums) count = Counter(nums)
if (factors == None): if (factors == None):
@ -17,17 +20,15 @@ def divisible(rng):
for key, value in count.items(): for key, value in count.items():
if (not factors[key] or value > factors[key]): if (not factors[key] or value > factors[key]):
factors[key] = value factors[key] = value
result = 1
return factors for key, value in factors.items():
factors = divisible(range(1, 21))
result = 1
for key, value in factors.items():
result *= key ** value result *= key ** value
return result
result = smallest_multiple(range(1, 21))
print(result) print(result)
print(result == target) print(result == target)