From a48f3608b2bfa9a81f2f1d29fa20f90cd787cb87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Engl=C3=B6f=20Ytterstr=C3=B6m?= Date: Tue, 19 Dec 2023 14:47:05 +0100 Subject: [PATCH] Cleanup 2015 solutions --- 2015-python/solutions/__init__.py | 6 ++--- 2015-python/solutions/day_06.py | 9 ++++++-- 2015-python/solutions/day_08.py | 2 -- 2015-python/solutions/day_19.py | 6 ++--- 2015-python/solutions/day_20.py | 37 +++++++++++-------------------- 2015-python/solutions/day_23.py | 10 --------- 2015-python/solutions/day_24.py | 7 ------ 7 files changed, 26 insertions(+), 51 deletions(-) diff --git a/2015-python/solutions/__init__.py b/2015-python/solutions/__init__.py index 3810ab4..d5c354e 100644 --- a/2015-python/solutions/__init__.py +++ b/2015-python/solutions/__init__.py @@ -23,10 +23,10 @@ class BaseSolution: ) def solve(self, puzzle_input): - raise NotImplemented + raise NotImplementedError def solve_again(self, puzzle_input): - raise NotImplemented + raise NotImplementedError def parse_input(self, data): - raise NotImplemented + raise NotImplementedError diff --git a/2015-python/solutions/day_06.py b/2015-python/solutions/day_06.py index 2252fd9..d61d0d5 100644 --- a/2015-python/solutions/day_06.py +++ b/2015-python/solutions/day_06.py @@ -1,7 +1,8 @@ import re -from solutions import BaseSolution from collections import defaultdict +from solutions import BaseSolution + class Solution(BaseSolution): input_file = "06.txt" @@ -26,6 +27,8 @@ class Solution(BaseSolution): m[(r, c)] = True case "turn off": m[(r, c)] = False + p1 = sum(m.values()) + assert p1 == 569999 return sum(m.values()) def solve_again(self, puzzle_input): @@ -42,7 +45,9 @@ class Solution(BaseSolution): m[(r, c)] += 1 case "turn off": m[(r, c)] = max(m[(r, c)] - 1, 0) - return sum(m.values()) + p2 = sum(m.values()) + assert p2 == 17836115 + return p2 if __name__ == "__main__": diff --git a/2015-python/solutions/day_08.py b/2015-python/solutions/day_08.py index b0a1ed2..5a3a67e 100644 --- a/2015-python/solutions/day_08.py +++ b/2015-python/solutions/day_08.py @@ -1,5 +1,3 @@ -import re - from solutions import BaseSolution diff --git a/2015-python/solutions/day_19.py b/2015-python/solutions/day_19.py index 119b990..c7c2a8b 100644 --- a/2015-python/solutions/day_19.py +++ b/2015-python/solutions/day_19.py @@ -1,7 +1,7 @@ -from collections import defaultdict -from solutions import BaseSolution import re -from random import shuffle, choice +from random import shuffle + +from solutions import BaseSolution class Solution(BaseSolution): diff --git a/2015-python/solutions/day_20.py b/2015-python/solutions/day_20.py index ca97d7c..20ae7db 100644 --- a/2015-python/solutions/day_20.py +++ b/2015-python/solutions/day_20.py @@ -1,4 +1,5 @@ from collections import defaultdict + from solutions import BaseSolution @@ -9,17 +10,17 @@ class Solution(BaseSolution): return "Day 20: Infinite Elves and Infinite Houses" def solve(self, pi): + hn = 831601 + x1 = defaultdict(int) + for i in range(1, hn): + for n in range(0, hn, i): + if n == 0: + continue + x1[n] += i * 10 + return max(x1.items(), key=lambda y: y[1])[0] + + def solve_again(self, pi): S = 36_000_000 - # hn = 831601 - # x1 = defaultdict(int) - # for i in range(1, hn): - # for n in range(0, hn, i): - # if n == 0: - # continue - # x1[n] += i * 10 - # for k, v in x1.items(): - # if v >= S: - # print(k, v) hn = 885000 hc = 50 x2 = defaultdict(int) @@ -28,12 +29,7 @@ class Solution(BaseSolution): if n == 0: continue x2[n] += i * 11 - # p1 = max(x1.items(), key=lambda y: y[1])[0] - p2 = min(filter(lambda x: x[1] >= S, x2.items()), key=lambda y: y[0])[0] - return 0, p2 - - def solve_again(self, pi): - return pi + return min(filter(lambda x: x[1] >= S, x2.items()), key=lambda y: y[0])[0] def parse_input(self, data): return data.strip() @@ -41,11 +37,4 @@ class Solution(BaseSolution): if __name__ == "__main__": solution = Solution() - # solution.show_results() - - dummy = """ - replace me - """.strip() - - print(solution.solve(dummy)) - # solution.solve_again(dummy) + solution.show_results() diff --git a/2015-python/solutions/day_23.py b/2015-python/solutions/day_23.py index a2b63f3..08015ea 100644 --- a/2015-python/solutions/day_23.py +++ b/2015-python/solutions/day_23.py @@ -53,13 +53,3 @@ class Solution(BaseSolution): if __name__ == "__main__": solution = Solution() solution.show_results() - - dummy = """ -inc a -jio a, +2 -tpl a -inc a -""".strip() - - # solution.solve(dummy) - # solution.solve_again(dummy) diff --git a/2015-python/solutions/day_24.py b/2015-python/solutions/day_24.py index 7a4a008..dc44436 100644 --- a/2015-python/solutions/day_24.py +++ b/2015-python/solutions/day_24.py @@ -41,10 +41,3 @@ class Solution(BaseSolution): if __name__ == "__main__": solution = Solution() solution.show_results() - - dummy = """ - 1,2,3,4,5,7,8,9,10,11 - """.strip() - - solution.solve(dummy) - # solution.solve_again(dummy)