aboutsummaryrefslogtreecommitdiff
path: root/2025/06/b.py
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-12-06 07:57:16 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-12-06 07:57:16 +0100
commitbe683b101393d3566261c9cc10351398bd2e1b6c (patch)
treeb8c47ad943a4f5cffd423ee04f6a931c4b276b89 /2025/06/b.py
parent424ffd61c58eb127f9a657a854737e2d82368217 (diff)
downloadaoc-be683b101393d3566261c9cc10351398bd2e1b6c.tar.gz
aoc-be683b101393d3566261c9cc10351398bd2e1b6c.zip
Day 6 2025 I suck
Diffstat (limited to '2025/06/b.py')
-rw-r--r--2025/06/b.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/2025/06/b.py b/2025/06/b.py
new file mode 100644
index 0000000..d52560f
--- /dev/null
+++ b/2025/06/b.py
@@ -0,0 +1,32 @@
1import fileinput
2from functools import reduce
3from operator import mul
4
5with fileinput.input() as lines:
6 all = list(lines)
7 a = [line[:-1] for line in all[:-1]]
8 op = all[-1][:-1]
9
10def sol(a, j, k):
11 nums = []
12 i = k-2
13 while i >= j:
14 n = 0
15 for r in a:
16 if r[i] != ' ':
17 n = 10*n + int(r[i])
18 nums.append(n)
19 i -= 1
20 return sum(nums) if op[j] == '+' else reduce(mul, nums, 1)
21
22j = 0
23s = 0
24while j < len(op):
25 k = j+1
26 while k < len(op) and op[k] == ' ':
27 k += 1
28 if k >= len(op):
29 k = max(len(r) for r in a)+1
30 s += sol(a, j, k)
31 j = k
32print(s)

Generated with cgit - Back to sebastiano.tronto.net