From be683b101393d3566261c9cc10351398bd2e1b6c Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 6 Dec 2025 07:57:16 +0100 Subject: Day 6 2025 I suck --- 2025/06/b.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 2025/06/b.py (limited to '2025/06/b.py') 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 @@ +import fileinput +from functools import reduce +from operator import mul + +with fileinput.input() as lines: + all = list(lines) + a = [line[:-1] for line in all[:-1]] + op = all[-1][:-1] + +def sol(a, j, k): + nums = [] + i = k-2 + while i >= j: + n = 0 + for r in a: + if r[i] != ' ': + n = 10*n + int(r[i]) + nums.append(n) + i -= 1 + return sum(nums) if op[j] == '+' else reduce(mul, nums, 1) + +j = 0 +s = 0 +while j < len(op): + k = j+1 + while k < len(op) and op[k] == ' ': + k += 1 + if k >= len(op): + k = max(len(r) for r in a)+1 + s += sol(a, j, k) + j = k +print(s) -- cgit v1.3