diff --git a/2024/09/README.md b/2024/09/README.md index 0a798ff..2715de8 100644 --- a/2024/09/README.md +++ b/2024/09/README.md @@ -58,3 +58,24 @@ The final step of this file-compacting process is to update the _filesystem chec Continuing the first example, the first few blocks' position multiplied by its file ID number are `0 * 0 = 0`, `1 * 0 = 0`, `2 * 9 = 18`, `3 * 9 = 27`, `4 * 8 = 32`, and so on. In this example, the checksum is the sum of these, _`1928`_. Compact the amphipod's hard drive using the process he requested. _What is the resulting filesystem checksum?_ (Be careful copy/pasting the input for this puzzle; it is a single, very long line.) + +### Part Two + +Upon completion, two things immediately become clear. First, the disk definitely has a lot more contiguous free space, just like the amphipod hoped. Second, the computer is running much more slowly! Maybe introducing all of that [file system fragmentation](https://en.wikipedia.org/wiki/File_system_fragmentation) was a bad idea? + +The eager amphipod already has a new plan: rather than move individual blocks, he'd like to try compacting the files on his disk by moving _whole files_ instead. + +This time, attempt to move whole files to the leftmost span of free space blocks that could fit the file. Attempt to move each file exactly once in order of _decreasing file ID number_ starting with the file with the highest file ID number. If there is no span of free space to the left of a file that is large enough to fit the file, the file does not move. + +The first example from above now proceeds differently: + + 00...111...2...333.44.5555.6666.777.888899 + 0099.111...2...333.44.5555.6666.777.8888.. + 0099.1117772...333.44.5555.6666.....8888.. + 0099.111777244.333....5555.6666.....8888.. + 00992111777.44.333....5555.6666.....8888.. + + +The process of updating the filesystem checksum is the same; now, this example's checksum would be _`2858`_. + +Start over, now compacting the amphipod's hard drive using this new method instead. _What is the resulting filesystem checksum?_ diff --git a/2024/09/part1.py b/2024/09/part1.py index c98cbcf..4ec186f 100644 --- a/2024/09/part1.py +++ b/2024/09/part1.py @@ -19,7 +19,7 @@ def disk_map_to_blocks(disk_map: str) -> list: return blocks -def move_ltr_to_empty_space(blocks: list) -> str: +def move_blocks_ltr_to_empty_space(blocks: list) -> str: left = 0 right = len(blocks) - 1 @@ -53,7 +53,7 @@ if __name__ == "__main__": print("Blocks:") print(blocks) - result = move_ltr_to_empty_space(blocks) + result = move_blocks_ltr_to_empty_space(blocks) if verbose: print()