From ac6b97590c1d51b46edb09f6ae34b78c6f424fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Engl=C3=B6f=20Ytterstr=C3=B6m?= Date: Thu, 4 Dec 2025 18:51:58 +0100 Subject: [PATCH] Solve 2025 day 4 pt 1-2 Had a bug in my aoc lib, that lost me an hour for pt 1: The ADJ dict has SW twice, and lacks NE. The bug is at least 2 years old. It was introduced in 661f18dca4 and apparently has never worked. I guess it has not been used up until now. That being said, it was straight-forward. A new helper for grid was used the first time, as well as an improved vdbg() function. --- 2025-python/output/day_04.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 2025-python/output/day_04.py diff --git a/2025-python/output/day_04.py b/2025-python/output/day_04.py new file mode 100644 index 0000000..63dc903 --- /dev/null +++ b/2025-python/output/day_04.py @@ -0,0 +1,31 @@ +from output import grid, ADJ + + +def solve(data): + p1 = 0 + p2 = set() + G = grid(data, o="@") + while True: + for r, c in G: + if sum((r + dy, c + dx) in G for dy, dx in ADJ) < 4: + p2.add((r, c)) + if p1 == 0: + p1 = len(p2) + if not G & p2: + break + G = G - p2 + p2 = len(p2) + return p1, p2 + + +if __name__ == "__main__": + with open("./input/04.txt", "r") as f: + inp = f.read().strip() + + p1, p2 = solve(inp) + + print(p1) + print(p2) + + assert p1 == 1493 + assert p2 == 9194