Discussion thread for day 18 of the Advent of Code - https://adventofcode.com/2024/day/18
Had fun with this one. If you struggled with it, take some time to look through other people's solutions. The skillset here, around iterative macros, distance calculations and checking for any possible path (vs. checking for the best one) comes up over and over on Advent problems and this one is a good example because it doesn't really have any extra complications.
Part2 was not so difficult than I thought it would be while solving part1.
This one was fun. Got to re-purpose an older workflow, then nearly tried brute forcing Part 2, but I caught myself after 3 iterations, and realized there was a much better way!
P1 was solved by very similer way with my day16 soltion.
P1 and P2
P1 macro
Day 18. More in spoiler
See above responses for much smarter solutions to part 2... but because I started this last night and quickly finished part 1 before going to bed, I thought I would see what the computer could do overnight while I slept with the brute force approach... turns out it works (just takes several hours). Posting this solution just to show that is CAN be done this way, not that it SHOULD be 🤣.
brute force but in reverse way. (from not clear to clear)
I believe it faster because it blocked (only explore half of the map, even lesser), and cause each iteration take is lesser time.
and the answer is near the end also, so it another huge time save.🤣
runtime 15mins, still long but i satisfied.
I was able to utilize the workflow from Day 16.
P1 was relatively straightforward, but I struggled with P2 as I couldn’t get the correct answer for quite some time. As the number of loops increased, the behavior became odd, so I displayed the maze in Excel to manually create one correct route. This helped me identify points where logic was wrong and I fixed the bug. It turned out there was a very simple bug that I hadn’t noticed in either Day16 or Day18 P1.
For P1, it runs within 100 iterations and completes in 37 seconds. Since the iterations for P2 reached nearly 200, I split the macro so it would stop as soon as even one route was found. P2 requires try and error but P2 can run in 1 sec.