working on part 2

This commit is contained in:
JISAUAY 2024-12-11 10:20:01 -06:00
parent 21421d265e
commit 025ecdb71d

View File

@ -57,6 +57,13 @@ class DiskMap:
return None 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: def compact(self) -> None:
while True: while True:
free_index = self.findFreeBlock() free_index = self.findFreeBlock()
@ -109,3 +116,5 @@ for block in diskmap.blocks:
index += 1 index += 1
print(f'Part 1: {total}') print(f'Part 1: {total}')