grid traversal with pattern matching - Day 16 - Advent of Code 2023

In this episode of the Advent of Code 2023 solutions series, we tackle day 16, The Floor Is Lava, using Ruby. We start by examining the puzzle input, representing a contraption through which a beam of light travels. The beam interacts with different components like mirrors, splitters, empty spaces, etc. Our goal is to follow the path of the beam and count the number of "energized" tiles it travels over.

First, we set up the input grid and beams data structures to track the position and direction of beam segments. We use a while loop to traverse the grid, using pattern matching to check the tile type ahead and turn, split beams, or continue on accordingly. We skip over seen tiles and handle edge cases.

For part 1, we print the number of energized tiles for the given input. For part 2, we maximize energy by checking all possible starting points along the edges. This results in a brute-force approach that takes several minutes to run. We make an optimization to use just 1 set instead of 2 to improve performance.

Overall, this solution leverages pattern matching, recursion, and data structures like arrays and sets. The video explains the code step-by-step and suggests further improvements as well. It's aimed at intermediate Ruby developers looking to strengthen their skills.

Advent of Code:
My Solutions:

#adventofcode #ruby