From 2d3caced7f3b0048194b3874d715972529aeaefa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Engl=C3=B6f=20Ytterstr=C3=B6m?= Date: Fri, 5 Dec 2025 08:27:05 +0100 Subject: [PATCH] Solve 2025 day 5 pt 1-2 Part 2 was too hard for me, since I initially worked with range(s, e). It quickly became out of hand. A funnel method was instead used. --- 2025-python/output/day_05.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 2025-python/output/day_05.py diff --git a/2025-python/output/day_05.py b/2025-python/output/day_05.py new file mode 100644 index 0000000..eda70e6 --- /dev/null +++ b/2025-python/output/day_05.py @@ -0,0 +1,31 @@ +from output import ints + + +def solve(data): + p1 = None + p2 = 0 + ranges, ids = data.split("\n\n") + ids = ints(ids) + R = [ints(line) for line in ranges.split()] + p1 = sum(any(s <= n <= e for s, e in R) for n in ids) + c = 0 + for s, e in sorted(R): + s = max(c + 1, s) + if s <= e: + p2 += e - s + 1 + c = max(e, c) + + return p1, p2 + + +if __name__ == "__main__": + with open("./input/05.txt", "r") as f: + inp = f.read().strip() + + p1, p2 = solve(inp) + + print(p1) + print(p2) + + assert p1 == 509 + assert p2 == 336790092076620