Day 10: Pipe Maze

AdventuRust - AoC 2023

This is Day 10 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 10, we're trying to make a loop in a pipe maze. We start by reading the input line by line and adding ins and outs for each square so that after we've parsed the entire input, we can link the outs to ins and form a loop. The start square is denoted by an S so we don't know the connections to its neighbors but we know that it can only connect to two neighbors which can help us figure out the connections. Once we solve for S, we can create a loop and the answer is half the length of the loop. Click here to jump to the part 2 discussion.

For part 2 of Day 10, we have to calculate the area enclosed by the loop. This took me a long time to debug despite knowing how to solve it. The key is to count the number of times we intersect the loop when we come to a square from a particular edge of the input. The tricky part here was that there is a difference between squares that are LJ and squares that are FJ. While the former has two intersections (and hence it's as if it wasn't there), the latter is the equivalent of a | and hence counts as a single intersection. I was really frustrated by this one, but it's done now. The amount of time I spent on this puzzle tells me that the day when I don't get the second star is close.

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

Cheers,
Devang