<- back

advent of code - day 5

2023-12-05

See the puzzle here.

See my full solution here.

Part 1

This part wasn't too bad. Honestly, the hardest thing here was just comprehending what the puzzle was talking about.

Once I understood what it was asking for, it was just a matter of traversing the maps to trace seed values to location values and finding the minimum.

Part 2

On the surface, part 2 sounded like it was just going to quickly be a slight modification of part 1, but boy was I wrong.

Slightly tweaking the seeds to be ranges instead of single values immediately resulted in:

Fatal JavaScript invalid size error 169220804

A quick google taught me that this meant that I exceeded the maximum array size allowed in javascript.

I was stuck on this for a while and tried a bunch of random ideas, but nothing really worked for me.

Eventually, I landed on a solution where I started from 0 and incremented through all possible locations. For each location, I worked backward through the maps checking what seed would have resulted in that location. Then I checked if any of the original seed ranges would have contained that seed. The first location that had a match was the answer.

I was nervous this solution would be too slow, but it ran in 1 or 2 seconds, so I was pleasantly surprised.