diff --git a/2025/d06.py b/2025/d06.py index 2ee7209..0e8945d 100644 --- a/2025/d06.py +++ b/2025/d06.py @@ -1,4 +1,7 @@ from lib import get_data +from typing import TypeVar + +T = TypeVar('T') data = """123 328 51 64 45 64 387 23 @@ -26,4 +29,32 @@ for xs in lines: assert False, "Unexpected op" print(r) +def split(xs: list[T], delim: T) -> list[list[T]]: + res = [[]] + for x in xs: + if x == delim: + res.append([]) + else: + res[-1].append(x) + return res + +chars_trans: list[tuple[str]] = list(zip(*[line for line in data.splitlines()])) +lines_trans: list[str] = list(map(lambda line: "".join(line).strip(), chars_trans)) +cols: list[list[str]] = split(lines_trans, '') + +r2 = 0 +for xs in cols: + x0 = xs[0] + acc, op = int(x0[:-1]), x0[-1] + for x in xs[1:]: + x = int(x) + if op == "+": + acc += x + elif op == "*": + acc *= x + else: + assert False, "Unexpected op" + r2 += acc + +print(r2)