Function aoc::y23d16::y23d16

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

The solution for the day sixteen challenge.

As usual we take the input as a string and an integer to determine the part. We start by parsing the input into a std::collections::HashMap grid. Then for part one we only have a single starting point so we can return the result immediately from the solver function. For part two we instead keep track of the energized tiles from each starting point and direction in a std::collections::BinaryHeap and then simply return the largest one by popping it after we’ve tried all of the combinations.

§Example

// probably read this from the input file...
let input = concat!(
    "......|...\\..\\...\n",
    "..../........|...\n",
    "....\\.-.../......\n",
    "......|....../...\n",
    ".................",
);
assert_eq!(y23d16(input, 1), 41);
assert_eq!(y23d16(input, 2), 41);