Restructure 5

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

19
0005.py
View File

@ -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,16 +20,14 @@ def divisible(rng):
for key, value in count.items():
if (not factors[key] or value > factors[key]):
factors[key] = value
result = 1
return factors
for key, value in factors.items():
result *= key ** value
return result
factors = divisible(range(1, 21))
result = 1
for key, value in factors.items():
result *= key ** value
result = smallest_multiple(range(1, 21))
print(result)
print(result == target)