Function aoc::y23d14::y23d14

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

The solution for the day fourteen challenge.

We take the input as a string and an integer for the part which changes whether we do a single tilt or 1,000,000,000 cycles of tilt north, west, south, and then east. We start by parsing the input into a std::collections::HashMap grid of, cube-shaped rocks, rounded rocks, and empty spaces. Then, in part one we just run a single north tilt and then count the load. In part two we do one billion cycles but we keep track of the end states that we’ve seen and at which count in the cycle so that when we find the loop, we can short-circuit the loop and then we count the load.

§Example

// probably read this from the input file...
let input = "...\n.#.\nO..";
assert_eq!(y23d14(input, 1), 3);
assert_eq!(y23d14(input, 2), 1);