diff --git a/2024/day9/main.py b/2024/day9/main.py index efe042f..a377a0e 100644 --- a/2024/day9/main.py +++ b/2024/day9/main.py @@ -57,6 +57,13 @@ class DiskMap: return None + def findFreeBlockOfBestFit(self, size: int) -> int | None: + for i, block in enumerate(self.blocks): + if type(block) == FreeBlock and block.size >= size: + return i + + return None + def compact(self) -> None: while True: free_index = self.findFreeBlock() @@ -109,3 +116,5 @@ for block in diskmap.blocks: index += 1 print(f'Part 1: {total}') + +