Ben Yafai

Advent Of Code

2nd December 2023

2023 - Day 2

Cube Conundrum

Pulling dice from a bag and counting how many were red, green and blue.

Part one of today's challenge was to check if the game was possible, given limits of each colour that we could pull.

Here's an example line:

Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red

I first started with a simple regex to pull out the Game number, and the full round of games, then exploded out each round into an individual game.

With a little more regex to grab the numbers and colours more easily, I compared them to our max values and, if the game was possible, added the game ID up.

Code


I used almost the same code for part two where instead of seeing if a game was possible, we counted the minimum number of dice to max sure the game is possible.

Code


I reckon there must be some better regex I could have done earlier on - definitly not my string point. I was glad I could re-use a bunch of the same code this time round though.

My full responses are found on GitHub