Module advent_of_code_2023::day_2
source · Expand description
This is my solution for Advent of Code - Day 2: Cube Conundrum
Game
s and Draw
s have structs to contain them. Most of the work is in parsing, which is quite heavily
subdivided:
Once the input is in the internal representation it is mostly composing everything together:
- Part 1:
sum_valid_game_ids
usesis_valid_game
for each line - Part 2:
sum_minimal_contents_powers
splits the logic for each line betweenminimal_contents
anddraw_power
Structs
- Draw 🔒A record of the cubes shown in a single draw from a bag
- Game 🔒A record of draws made with a specific combination of cubes
Functions
- Given a draw, its “power” is the cube counts multiplied together
- Do any draws have more than the expected number of cubes
- Find the most cubes seen of each colour across the draws, giving the minimum number of each that must be in the bag
- Parse e.g.
17 green
as a numeric count and the colour string - Parse a comma separated list of drawn cubes as a
Draw
- Parse a line of the puzzle input as a
Game
- parse_id 🔒Parse
Game {{ id }}
as a numeric id - Parse the puzzle input treating each line as a game specification
- The entry point for running the solutions with the ‘real’ puzzle input.
- This is the solution to part 2 - delegates finding the minimal bag contents to
minimal_contents
and turning each bag into it’s power withdraw_power
- This is the solution to part 1 - delegates validity to
is_valid_game