From 956d461e3d6f992e4c5effbd689c7601fea2f0d0 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Wed, 5 Dec 2018 15:22:54 +1030 Subject: [PATCH] Added 2015 day20 --- 2015/day20.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/2015/day20.py b/2015/day20.py index 69cf632..ab5bb79 100644 --- a/2015/day20.py +++ b/2015/day20.py @@ -1,8 +1,15 @@ -for i in range(1, 500001): - presents = 0 - for n in range(1, i+1): - if i%n == 0: - presents += 10*n - if presents >= 33100000: - print(i, presents) - break +import numpy as np +max_it = 813960 # Somewhat cheaty - this value was obtained from an earlier factor-based brute force. Just use an arbitrarily large number if it fails. +input = 33100000 + +houses = np.ones([max_it], dtype=np.int64) +pres10 = input//10 +for i in range(2, max_it): + houses[i::i] += i +print(np.argmax(houses > pres10)) # Part 1 + +houses_2 = np.ones([max_it], dtype=np.int64) +pres11 = input//11 +for i in range(2, max_it): + houses_2[i:i*51:i] += i +print(np.argmax(houses_2 > pres11)) # Part 2