pub fn y22d10p2(input: &str) -> String
Expand description
The solution for part two of the day ten challenge.
I initially found the part two prompt somewhat challenging because I had a hard time understanding exactly how the drawing process worked based on the given instructions. After figuring it out it also became pretty straightforward.
Once we compute the cycles (we need to have 240 of them for the 6x40
size screen defined in the prompt) we commence the drawing process: go
pixel by pixel filling in each column left to right starting at the top
row and then proceeding to the next row after filling in all of the
columns. At each pixel we stop to consider the state of the register at
that point in time (each pixel corresponds to on cycle so rows > 0 mean
that we do the cycle lookup by multiplying the current row by 40
). If
the current column falls in the range of register +/-1 then we draw the
#
character, otherwise the .
character.
§Example
// probably read this from the input file...
let input = "noop\n".repeat(240);
assert_eq!(y22d10p2(&input),
"###.....................................\n".repeat(6).trim()
);