Refactor 2023 for new system.

This commit is contained in:
Mikael CAPELLE
2024-12-04 17:09:24 +01:00
parent a9bcf9ef8f
commit 664dcfe7ba
24 changed files with 1119 additions and 1085 deletions

View File

@@ -1,29 +1,34 @@
import sys
from typing import Any, Iterator
lines = sys.stdin.read().splitlines()
from ..base import BaseSolver
data = [[int(c) for c in line.split()] for line in lines]
right_values: list[int] = []
left_values: list[int] = []
for values in data:
diffs = [values]
while any(d != 0 for d in diffs[-1]):
diffs.append([rhs - lhs for lhs, rhs in zip(diffs[-1][:-1], diffs[-1][1:])])
class Solver(BaseSolver):
def solve(self, input: str) -> Iterator[Any]:
lines = input.splitlines()
rhs: list[int] = [0]
lhs: list[int] = [0]
for cx in range(len(diffs) - 1):
rhs.append(diffs[-cx - 2][-1] + rhs[cx])
lhs.append(diffs[-cx - 2][0] - lhs[cx])
data = [[int(c) for c in line.split()] for line in lines]
right_values.append(rhs[-1])
left_values.append(lhs[-1])
right_values: list[int] = []
left_values: list[int] = []
for values in data:
diffs = [values]
while any(d != 0 for d in diffs[-1]):
diffs.append(
[rhs - lhs for lhs, rhs in zip(diffs[-1][:-1], diffs[-1][1:])]
)
# part 1
answer_1 = sum(right_values)
print(f"answer 1 is {answer_1}")
rhs: list[int] = [0]
lhs: list[int] = [0]
for cx in range(len(diffs) - 1):
rhs.append(diffs[-cx - 2][-1] + rhs[cx])
lhs.append(diffs[-cx - 2][0] - lhs[cx])
# part 2
answer_2 = sum(left_values)
print(f"answer 2 is {answer_2}")
right_values.append(rhs[-1])
left_values.append(lhs[-1])
# part 1
yield sum(right_values)
# part 2
yield sum(left_values)