Function aoc::y15d06::y15d06p1

source ·
pub fn y15d06p1(input: &str) -> u32
Expand description

The solution for part one of the day six challenge.

Given the input as a string we start by building a 1000x1000 grid of booleans that represent the state of each light in each position. All of the lights start “off” (false). We then parse each instruction and loop through the lights in the instruction, turning them on or off as necessary. Finally, we make one final pass through every light and increment our final counter if the light is on and then return that final sum.

§Example

// probably read this from the input file...
let input = concat![
  "turn on 12,12 through 40,40\n",
  "turn off 10,10 through 23,23\n",
  "turn on 15,14 through 16,15\n",
  "toggle 20,21 through 22,21\n",
];
assert_eq!(y15d06p1(input), 704);