Skip to content

Commit 67b4496

Browse files
committed
Add solution to 2025-12-06
1 parent 887cec2 commit 67b4496

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

2025/day06/solutions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from itertools import pairwise
2+
from math import prod
3+
4+
with open("input") as f:
5+
*nums_lines, ops_line, _ = f.read().split("\n")
6+
7+
data = [(i, op) for i, x in enumerate(ops_line) if (op := {"+": sum, "*": prod}.get(x))]
8+
indices, ops = zip(*data)
9+
10+
# Part 1
11+
nums1 = [
12+
[line[start : end - 1] for line in nums_lines]
13+
for start, end in pairwise([*indices, len(ops_line) + 1])
14+
]
15+
16+
# Part 2
17+
nums2 = (map("".join, zip(*ns)) for ns in nums1)
18+
19+
for nums in (nums1, nums2):
20+
print(sum(op(map(int, col)) for op, col in zip(ops, nums)))

0 commit comments

Comments
 (0)