pub fn y23d15(input: &str, part: u32) -> u32
Expand description
The solution for the day fifteen challenge.
We take the input as usual along with the normal integer to determine part
1
or part 2
. In part one we just split the input by “,” and then
calculate the hash for each string. For part two we instead build two
vectors to keep track of the current values of each label (using
std::collections::HashMap
) as well as the orders of the labels in a
separate vector. This could probably be simplified to use just a single
vector with a tuple value. After we process the input step-by-step all that
is left is to calculate the power based on the prompt instructions.
§Example
// probably read this from the input file...
let input = "ab=1,cd=2,ef=3,cd-,ab=4";
assert_eq!(y23d15(input, 1), 746);
assert_eq!(y23d15(input, 2), 628);