Day 8: Haunted Wasteland

AdventuRust - AoC 2023

This is Day 8 of Advent of Code 2023! If you would like to solve the problems before looking at the solution, you can find them here.

In part 1 of Day 8, we're following some directions to get from a start point (AAA) to an end point (ZZZ). The input is of the form Source = (Left_Destination, Right_Destination) and the order of Left/Right moves is described in the first line. Pretty straightforward solution but I got to use the loop() functionality, essentially a while True but it looks cleaner. The length of the path taken is the answer to part 1. Click here to jump to the part 2 discussion.

For part 2 of Day 8, we now have multiple starting points, and we can't stop still all the paths have reached their end at the exact same step. I tried brute forcing this but it ran for a while, so I tried to come up with another solution. I realized that the paths are loops that keep repeating, which means that we need to come up with a path length that is a multiple of all the different path lengths, i.e. the least common multiple. Once we figure that out, the code runs much faster, and you're done. In order to determine the LCM, I used the lcm function from the num_integer crate.

That's all folks! If you made it this far, enjoy some AI art generated by u/dimpopo using the prompt for this puzzle.