advent of code - day 8
2023-12-08
See the puzzle here.
See my full solution here.
Part 1
Once again, this part was pretty straight-forward. I just loaded the input into an object where the key was the current node I'm on and the value was an object containing the node to the left and the node to the right.
I iterated over the LR instructions and would lookup in the object what the next node was. If I landed on ZZZ I would stop.
Part 2
I suspected there was a trick, but I still first tried tweaking my part 1 code to just brute force look for the answer. I let it run in the background while I tried to figure out the trick. (Spoiler: there was a trick and it never completed).
Since I did advent of code last year, I figured out the trick pretty quickly, but if you hadn't done advent of code in the past, the trick might have been hard to spot.
The trick was to find the shortest path to a node ending in Z from each starting node, then find the least common multiple of all of these paths.
This was an insanely high number and there's no chance my brute force solution would have ever gotten to it.