From 044df2499049b4494ca892e3dd619cff1bfc71a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Engl=C3=B6f=20Ytterstr=C3=B6m?= Date: Thu, 11 Dec 2025 21:42:15 +0100 Subject: [PATCH] Solve 2025 day 11 pt 1-2 For p1 a BFS algorithm is fast enough. For pt 2, for the third day in a row, it did not work. I caved in and used recursion and memoisation for DFS instead, instantly fast as lightning. I finished by making the pt 2 code compatible with pt 1. --- 2025-python/output/day_11.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 2025-python/output/day_11.py diff --git a/2025-python/output/day_11.py b/2025-python/output/day_11.py new file mode 100644 index 0000000..61b7a0f --- /dev/null +++ b/2025-python/output/day_11.py @@ -0,0 +1,33 @@ +import functools +from collections import defaultdict + + +def solve(data): + G = defaultdict(set) + for line in data.splitlines(): + f, *t = line.split() + G[f[:-1]] = set(t) + + @functools.cache + def _traverse(k, fasttrack=True, fft=False, dac=False): + if k == "out": + return fasttrack or (fft and dac) + return sum( + _traverse(nk, fasttrack, fft or k == "fft", dac or k == "dac") + for nk in G[k] + ) + + return _traverse("you"), _traverse("svr", fasttrack=False) + + +if __name__ == "__main__": + with open("./input/11.txt", "r") as f: + inp = f.read().strip() + + p1, p2 = solve(inp) + + print(p1) + print(p2) + + assert p1 == 649 + assert p2 == 458948453421420