Function aoc::y23d02::y23d02

source ·
pub fn y23d02(input: &str, part: u32) -> u32
Expand description

The solution for the day two challenge.

As usual, we take the input as a string and an integer denoting the part of the problem that we want to solve. In part 1 we return the sum of the game numbers of the games that are possible, and in part 2 we instead return the sum of the “powers” of the games (more information about how to compute the power is in the prompt but basically the minimum number of red, blue, and green cubes multiplies together). After we parse the input we switch on the part and either check if the game is possible and add its number to the sum or compute its power and add it to the sum.

§Example

// probably read this from the input file...
let input = concat!(
    "Game 1: 20 red, 20 blue, 20 green\n",
    "Game 2: 5 red, 5 blue, 5 green",
);
assert_eq!(y23d02(input, 1), 2);
assert_eq!(y23d02(input, 2), 8125);