Start refactoring code better flexibility.

This commit is contained in:
Mikael CAPELLE
2024-12-04 16:03:37 +01:00
parent 1caf93b38b
commit a9bcf9ef8f
30 changed files with 384 additions and 403 deletions

View File

@@ -1,14 +1,17 @@
import sys
from collections import Counter
from typing import Any, Iterator
values = list(map(int, sys.stdin.read().strip().split()))
from ..base import BaseSolver
column_1 = sorted(values[::2])
column_2 = sorted(values[1::2])
counter_2 = Counter(column_2)
answer_1 = sum(abs(v1 - v2) for v1, v2 in zip(column_1, column_2, strict=True))
answer_2 = sum(value * counter_2.get(value, 0) for value in column_1)
class Solver(BaseSolver):
def solve(self, input: str) -> Iterator[Any]:
values = list(map(int, input.split()))
print(f"answer 1 is {answer_1}")
print(f"answer 2 is {answer_2}")
column_1 = sorted(values[::2])
column_2 = sorted(values[1::2])
yield sum(abs(v1 - v2) for v1, v2 in zip(column_1, column_2, strict=True))
counter_2 = Counter(column_2)
yield sum(value * counter_2.get(value, 0) for value in column_1)