Pattern matching with Ranges - Day 02 - Advent of Code 2023

In this video, you'll see a Ruby solution to parse the input data, model Game and Round classes, and determine which games meet the validity criteria for the Day 02, 2023 advent of code challenge.

We'll start by parsing the input to extract the game ID and rounds. Then build out Game and Round classes to represent the data. Next we'll create a #possible? method to check if a game meets the criteria of only having 12 red, 13 green, and 14 blue cubes.

For part 2, we'll find the minimum possible cubes needed to make each game valid. I refactor my solution to leverage Ruby iterator methods like #each_with_object and #all?. Finally, I use Ruby 3.1's new pattern matching on ranges for a clean validation check.


Advent of Code: https://adventofcode.com/
My Solutions: https://gist.github.com/cjavdev/d15a2a4ffed6c840c2fb28a093e9f927/
Playlist https://www.youtube.com/playlist?list=PLS6F722u-R6KYlGyUv65EFpGKl2Esmurr

#adventofcode #ruby