From 0723a8223f466c82398b30306e82ab63d56e1a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Engl=C3=B6f=20Ytterstr=C3=B6m?= Date: Thu, 11 Dec 2025 20:45:13 +0100 Subject: [PATCH] day 10 --- 2025-python/output/day_10.py | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 2025-python/output/day_10.py diff --git a/2025-python/output/day_10.py b/2025-python/output/day_10.py new file mode 100644 index 0000000..c33f965 --- /dev/null +++ b/2025-python/output/day_10.py @@ -0,0 +1,58 @@ +import re +from pprint import pprint +from collections import deque, Counter, defaultdict +from heapq import heappop, heappush +from itertools import compress, combinations, chain, permutations + +from output import matrix, D, DD, ADJ, ints, sints, mhd, mdbg, vdbg, cw, ccw, bk + + +def solve(data): + r = r"^\[(.+)\] (.+) \{(.+)\}$" + p1 = 0 + for line in data.splitlines(): + il, b, _j = re.findall(r, line)[0] + B = [set(ints(s)) for s in b.split()] + E = set([i for i, s in enumerate(il) if s == "#"]) + Q = [(b, set(), 0) for b in B] + while Q: + b, lit, p = Q.pop(0) + if lit == E: + p1 += p + break + for nb in B: + if nb == b: + continue + Q.append((nb, lit ^ b, p + 1)) + p2 = None + return p1, p2 + + +if __name__ == "__main__": + import os + + # use dummy data + inp = """ +[.##.] (3) (1,3) (2) (2,3) (0,2) (0,1) {3,5,4,7} +[...#.] (0,2,3,4) (2,3) (0,4) (0,1,2) (1,2,3,4) {7,5,12,7,2} +[.###.#] (0,1,2,3,4) (0,3,4) (0,1,2,4,5) (1,2) {10,11,11,5,10,5} """.strip() + + # uncomment to instead use stdin + # import sys; inp = sys.stdin.read().strip() + + # uncomment to use AoC provided puzzle input + with open("./input/10.txt", "r") as f: + inp = f.read().strip() + + # uncomment to do initial data processing shared by part 1-2 + p1, p2 = solve(inp) + + print(p1) + os.system(f"echo {p1} | wl-copy") + # print(p2) + # os.system(f"echo {p2} | wl-copy") + + # uncomment and replace 0 with actual output to refactor code + # and ensure nonbreaking changes + # assert p1 == 0 + # assert p2 == 0