mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
28 lines
680 B
Python
28 lines
680 B
Python
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))
|