We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 887cec2 commit d9baf00Copy full SHA for d9baf00
2025/day06/solutions.py
@@ -0,0 +1,19 @@
1
+from math import prod
2
+
3
+with open("input") as f:
4
+ *num_lines, ops_line, _ = f.read().split("\n")
5
6
+indices = [i for i, x in enumerate(ops_line) if x != " "]
7
+ops = [{"+": sum, "*": prod}[ops_line[i]] for i in indices]
8
9
+# Part 1
10
+nums1 = [
11
+ [line[start : end - 1] for line in num_lines]
12
+ for start, end in zip(indices, indices[1:] + [len(ops_line) + 1])
13
+]
14
15
+# Part 2
16
+nums2 = [map("".join, zip(*ns)) for ns in nums1]
17
18
+for nums in (nums1, nums2):
19
+ print(sum(op(map(int, col)) for op, col in zip(ops, nums)))
0 commit comments