diff --git a/day01.py b/day01.py index 3a01bee..d1920b5 100644 --- a/day01.py +++ b/day01.py @@ -17,7 +17,7 @@ class Day(AOCDay): ] ] - def parse_input(self) -> (list, list): + def parse_input(self) -> tuple[list, list]: lefts, rights = [], [] for line in self.getInput(): left, right = map(int, line.split()) @@ -32,8 +32,8 @@ class Day(AOCDay): def part2(self) -> Any: lefts, rights = self.parse_input() - rights = Counter(rights) - return sum(num * rights[num] for num in lefts) + counted = Counter(rights) + return sum(num * counted[num] for num in lefts) if __name__ == '__main__': diff --git a/day09.py b/day09.py index cc532d2..020fc85 100644 --- a/day09.py +++ b/day09.py @@ -21,7 +21,6 @@ def get_checksum(head: Block) -> int: index = head count = 0 while index is not None: - print((str(index.file_id) + "|") * index.file_length, end="") if index.file_id > 0: for _ in range(index.file_length): checksum += index.file_id * count @@ -30,7 +29,6 @@ def get_checksum(head: Block) -> int: count += index.file_length index = index.right - print() return checksum @@ -42,7 +40,7 @@ class Day(AOCDay): ], [ (2858, "input9_test"), - (None, "input9"), + (6373055193464, "input9"), ], ] @@ -102,6 +100,9 @@ class Day(AOCDay): index = tail while index is not None: + while index.file_id == -1: + index = index.left + search = head while search != index: if search.file_id == -1 and search.file_length >= index.file_length: @@ -120,8 +121,8 @@ class Day(AOCDay): search.right.left = new_space search.right = new_space - index = new_free_space break + search = search.right index = index.left