Discussion thread for day 8 of the Advent of Code - https://adventofcode.com/2023/day/8
Part2 was tough again.
Today was terrible... very challenging, wasted a lot of time expecting a large answer for Part 1, so I wasted an extra couple hours there. I did finish though, which is good. I also learned a few things along the way, which is even better!
- Simple parsing.
- Part 2 macro is an update on 1, to do a join and amend the logic to search for ending letters.
- Needed to use other methods *cough* to find the LCM but knew that was the approach so looped through each starting value, but should really have put this in a batch macro. So will need to check out @CoG LCM macro.
my last bit for part 2 isn't dynamic, and thank goodness for AMP which went much faster.
P1 was easy enough brute force. P2 in spoiler
Interesting puzzle! Frustrating to solve, but I learned a lot :) This takes longer to run than I would like, but it's manageable.
I'd actually love to revisit this one sometime when I'm fresh to optimize my approach. Lots of food for thought with this puzzle without completely wrecking my brain like Day 5 did.
Part 1: Brute force. Traverse every node based on the input directions until I hit ZZZ. Used an iterative macro.
I was proud of my formula to evaluate which direction to follow for each iteration: Mod([Engine.IterationNumber],Length([Source_data]))
Macro:
Part 2: Per usual, I tried to brute force this and felt really good about my logic... until I saw it creeping up to 500k iterations. It was sometime around then that I not only knew there had to be a mathematical solution, but that I'd have to figure it out in order to solve the puzzle. This workflow would never finish running otherwise.
After some rubber ducky debugging, I remembered something about Least Common Multiples from elementary school math and went to work. This is, I'm sure, far from the most efficient solution, but here's how I did it:
Batch Macro:
Iterative Macro:
Whole Workflow:
I'm still finding AoC fun but it's getting a little wild! Part 2 had me researching math algorithms...
Special thanks to @estherb47 for an old thread on [redacted]
Day 8 done! Part 1 and 2 macros look so different as I had stupidly been generating the instructions within the iterations for part 1 and changed that for the second part. Like others, I just ran each 'A' instance one-by-one using a batch macro that wrapped the path iterator, then took the LCM for the answer. A very fun one today!