From 05c7b5bfb98471b6a4ea8c82e05da13af8bac7e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Engl=C3=B6f=20Ytterstr=C3=B6m?= Date: Sat, 6 Dec 2025 07:55:40 +0100 Subject: [PATCH] Solve 2025 day 6 pt 1-2 Lost 20 minutes in pt 1 not rembering that a print() of a zip consumes it and makes it not loopable: had I just used list(zip()) or removed the print, I would have had the answer in a decent time frame. Pt 2 was fun! I first experienced with ljust() and rjust(), only to realize the input was mixed. Instead, I threated the input as a grid. --- 2025-python/output/day_06.py | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 2025-python/output/day_06.py diff --git a/2025-python/output/day_06.py b/2025-python/output/day_06.py new file mode 100644 index 0000000..8e396c7 --- /dev/null +++ b/2025-python/output/day_06.py @@ -0,0 +1,40 @@ +import re +from math import prod + + +def solve(data): + p1 = 0 + p2 = 0 + rows = data.splitlines() + J = max(len(r) for r in rows) + 1 + rows = [r.ljust(J) for r in rows] + ops = rows.pop() + s = 0 + for ows in re.findall(r"(\S\s+)", ops): + o, *ws = ows + e = s + len(ws) + col = [ns for ns in [r[s:e] for r in rows]] + s += len(ows) + col1 = [int(r) for r in col] + col2 = [int("".join([nsc for nsc in ns if nsc.isdigit()])) for ns in zip(*col)] + match o: + case "*": + p1 += prod(col1) + p2 += prod(col2) + case "+": + p1 += sum(col1) + p2 += sum(col2) + return p1, p2 + + +if __name__ == "__main__": + with open("./input/06.txt", "r") as f: + inp = f.read().strip() + + p1, p2 = solve(inp) + + print(p1) + print(p2) + + assert p1 == 5524274308182 + assert p2 == 8843673199391