Solution for day 20.

This commit is contained in:
Bert Peters
2015-12-20 23:07:26 +01:00
parent 337d2ed0c2
commit f89f413c63

27
day-20/solution.py Normal file
View File

@@ -0,0 +1,27 @@
from __future__ import print_function
def findFirst(data, target):
for idx, value in enumerate(data):
if value >= target:
return idx
return None
target = 34000000
# Target is achieved at itself/10, so reasonable upper bound.
upperbound = target // 10
# Use a varation of Erathostenes' sieve to compute the results
sieve1 = [10] * (upperbound + 1)
sieve2 = [10] * (upperbound + 1)
for x in range(1, upperbound):
for y in range(x, upperbound, x):
sieve1[y] += 10 * x
for y in range(x, min(50 * x, upperbound) + 1, x):
sieve2[y] += 11 * x
print("House", findFirst(sieve1, target))
print("House", findFirst(sieve2, target))