From f89f413c63920cd6f54c4cb9e95aaf5b6ead496d Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Sun, 20 Dec 2015 23:07:26 +0100 Subject: [PATCH] Solution for day 20. --- day-20/solution.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 day-20/solution.py diff --git a/day-20/solution.py b/day-20/solution.py new file mode 100644 index 0000000..e4d6aff --- /dev/null +++ b/day-20/solution.py @@ -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))