AoC# 2024 - Day 9: Disk Fragmenter

1 minute read

It’s Advent of Code time 🎄

Advent of Code is an Advent calendar of small programming puzzles for a variety of skill levels that can be solved in any programming language you like.

It took a change of approach to solve Day 9’s part 2, but I got there 🙂

Part 1 ⭐️

Time travelling with the engineers and reading the problem statement made me think of Quantum Leap this morning…

Took a deep breath, started breaking down the problem into functions and before I knew it I had a working solution. It took 6 secs to compute mind!

Part 2 ⭐️

Took another deep breath (!), and tweaked my Part 1. When the answer I got was too low for the example input I re-read the instructions and realised I’d completely misunderstood them 😔

After fixing my understanding and my code, I ran it against the full-fat input and when it hadn’t resolved in 20 seconds I went for breakfast. 20 minutes later it still hadn’t finished but I’d been thinking of using and manipulating a collection of Gap objects rather than repeatedly looping over the collection of File objects looking for gaps.

Another 20 minutes or so and with one wrong attempt (due to a susequently easily spotted bug), I had the second star. Compute was less than 150 ms too 🤓

Updated: