Will Thomas' blog

AoC 2025 Days 4 and 5

2025-12-22, Monday


Managed to blast through day 4, though I've been too busy to write it up here, and the first part of day 5. D5 part 2 though, oof!

Day 4 was quite a simple task, to find elements in a grid which had fewer than 4 neighbours also filled in. Then part 2 was simply a matter of repeating this process until there were no more valid targets. Simple, but nice; coming from a Computer Games Programming background, I enjoy this kind of thing; a visual representation of objects in space, changing states. Good fun!

Day 5 on the other hand, ouch. Part 1 not so bad, you have a list of lists, and must determine which numbers from another list aren't present in any of the previous lists. Fair enough.

Day 5 part 2 is where things really kicked off. It seems relatively straightforward, count up how many numbers are contained in all the ranges of numbers. My first attempt was running for a very long time, and I ended up cancelling it; adding some logging showed that some ranges ended lower than they began, so the for loop was going up forever. But this didn't seem right, and I remembered that there's usually a puzzle each year which involves numbers so stupendously huge that you have to figure out interacting with your language's BigInt structure, a construct designed for handling abnormally big numbers. Pipe that in and it gets better, but there's still some issues, and the best answer I can get is too high.

Add in some more logging, and it's hard to tell if maybe when combining ranges down, it's getting some wrong or not combining when it should. So I make it sort the ranges first, so I can check they're all combining down correctly and not missing any. But in doing this, I get a new, lower answer. I check some of the logging anyway, and all seems right, so I try the answer and it's now correct. Perhaps, by being in order before combining down, it just works better and more correctly.

No idea, but what we do know is now it works! Check out my terrible code here if you're interested.

See ya!