Skip to content

Commit

Permalink
2024/09 writeup
Browse files Browse the repository at this point in the history
  • Loading branch information
encse committed Dec 10, 2024
1 parent 32709e5 commit ab09b35
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 2024/Day09/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ Another push of the button leaves you in the familiar hallways of some friendly
While The Historians quickly figure out how to pilot these things, you notice an amphipod in the corner struggling with his computer. He's trying to make more contiguous free space by compacting all of the files, but his program isn't working; you offer to help.

Read the [full puzzle](https://adventofcode.com/2024/day/9).

I'm taking a break from using LINQ today and turning my attention to the low-level world of linked lists instead. I discovered a way to express both paths using a single `CompactFs` function with a `fragmentsEnabled` parameter. `CompactFs` operates with two pointers, `i` and `j`, which define the scan range we’re working on. `i` starts at the beginning of the disk, while `j` starts at the end and moves backward. When `i` points to a free space and `j` points to a used space, we call `RelocateBlock`, which moves `j` (or parts of `j`, depending on whether fragmentation is enabled) to a free space found after `i`.

The rest involves careful pointer arithmetic and linked list management, where I aim to avoid overwriting the data I’ll need in the next line. I find this surprisingly hard to get right when working with linked lists...

0 comments on commit ab09b35

Please sign in to comment.