generated from public/aoc_template
69 lines
1.5 KiB
Python
69 lines
1.5 KiB
Python
from tools.aoc import AOCDay
|
|
from tools.math import mul
|
|
from typing import Any
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(4277556, "input6_test"),
|
|
(4076006202939, "input6"),
|
|
],
|
|
[
|
|
(3263827, "input6_test"),
|
|
(7903168391557, "input6"),
|
|
]
|
|
]
|
|
|
|
def parse_input(self) -> list[tuple[list[int], int]]:
|
|
p = [l.split() for l in self.getInput()]
|
|
l = len(p[0])
|
|
r = []
|
|
for x in range(l):
|
|
r.append([y[x] for y in p])
|
|
|
|
return [(list(map(int, x[:-1])), x[-1]) for x in r]
|
|
|
|
|
|
def part1(self) -> Any:
|
|
ans = 0
|
|
for numbers, op in self.parse_input():
|
|
if op == '+':
|
|
ans += sum(numbers)
|
|
else:
|
|
ans += mul(numbers)
|
|
|
|
return ans
|
|
|
|
def part2(self) -> Any:
|
|
lines = self.getInput()
|
|
ops = lines[-1].split()
|
|
l = max(len(x) for x in lines)
|
|
rotated = []
|
|
for i in range(l):
|
|
rotated.append("".join(x[i] if len(x) > i else " " for x in lines[:-1]))
|
|
|
|
i = 0
|
|
ans = 0
|
|
total = 0 if ops[0] == '+' else 1
|
|
for n in rotated:
|
|
if not n.strip():
|
|
ans += total
|
|
i += 1
|
|
total = 0 if ops[i] == '+' else 1
|
|
continue
|
|
|
|
if ops[i] == '+':
|
|
total += int(n)
|
|
else:
|
|
total *= int(n)
|
|
|
|
ans += total
|
|
|
|
return ans
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2025, 6)
|
|
day.run(verbose=True)
|