Expand description

This is my solution for Advent of Code - Day 2: Cube Conundrum

Games and Draws 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:

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

  • draw_power 🔒
    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_cube 🔒
    Parse e.g. 17 green as a numeric count and the colour string
  • parse_draw 🔒
    Parse a comma separated list of drawn cubes as a Draw
  • parse_game 🔒
    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 with draw_power
  • This is the solution to part 1 - delegates validity to is_valid_game