2024 Day 9: Disk Fragmenter

Not really happy with my solution for part 2. I struggled to come up with the right data structure(s) until I worked backwards and wrote the algorithm first, then created the structures I needed for that algorithm. It’s sloppy and built on top of the map/vector I used in Part 1, even though those are clunky and unnecessary.

I tried rewriting it to maintain a free list and allocate from that like some of the other solutions I saw on reddit, but somehow that ended up being even slower.

I’m tired of messing with it, so this one is going in the “good enough” bucket for me.

I could image a faster solution, but that would have been more work. The one I wrote is fast enough. The given algorithm is nothing like a decent defragmenter anyway, so I didn’t feel the need to make it optimal.