Skip to content

Commit

Permalink
day1
Browse files Browse the repository at this point in the history
  • Loading branch information
Stegallo committed Dec 1, 2024
1 parent 5dde348 commit 8b0d7b2
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions y_2024/day1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import Counter
from typing import Optional

from pydantic.dataclasses import dataclass
Expand All @@ -8,25 +9,30 @@
@dataclass
class Row:
original: str
processed: Optional[str] = None
processed: Optional[list] = None

def __post_init__(self) -> None:
self.processed = "" # self.original
self.processed = self.original.split()


class Day(AoCDay):
def __init__(self, test=0):
super().__init__(__name__, test)

def _preprocess_input(self):
# self.__input_data = [[int(i) for i in chunk] for chunk in self._input_data]
print(f"{self._input_data=}")
self.__input_data = [Row(i) for i in self._input_data[0]]
parsed_input = [Row(i) for i in self._input_data[0]]
self.__first_list = [int(i.processed[0]) for i in parsed_input]
self.__second_list = [int(i.processed[1]) for i in parsed_input]

def _calculate_1(self):
for x in self.__input_data:
print(f"{x}")
return 0
result = 0
for x, y in zip(sorted(self.__first_list), sorted(self.__second_list)):
result += abs(y - x)
return result

def _calculate_2(self):
return 0
result = 0
c = Counter(self.__second_list)
for x in self.__first_list:
result += x * c.get(x, 0)
return result

0 comments on commit 8b0d7b2

Please sign in to comment.