-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from Stegallo/2024
2024
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,3 +129,5 @@ dmypy.json | |
.pyre/ | ||
input_day*.txt | ||
y_2022/secret_backup.py | ||
_old_y*/* | ||
gpt.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from collections import Counter | ||
from typing import Optional | ||
|
||
from pydantic.dataclasses import dataclass | ||
|
||
from common.aoc import AoCDay | ||
|
||
|
||
@dataclass | ||
class Row: | ||
original: str | ||
processed: Optional[list] = None | ||
|
||
def __post_init__(self) -> None: | ||
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=}") | ||
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): | ||
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): | ||
result = 0 | ||
c = Counter(self.__second_list) | ||
for x in self.__first_list: | ||
result += x * c.get(x, 0) | ||
return result |