2022-12-09 22:57:22 -08:00
|
|
|
use IO, Map;
|
|
|
|
|
|
|
|
iter ops() {
|
2022-12-09 22:57:32 -08:00
|
|
|
yield 1; // Initial state
|
2022-12-09 22:57:22 -08:00
|
|
|
for line in stdin.lines().strip() {
|
2022-12-09 22:57:32 -08:00
|
|
|
select line[0..3] {
|
|
|
|
when "noop" do yield 0;
|
|
|
|
when "addx" {
|
|
|
|
yield 0;
|
|
|
|
yield line[5..] : int;
|
|
|
|
}
|
2022-12-09 22:57:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 22:57:32 -08:00
|
|
|
const deltas = ops();
|
|
|
|
const states = + scan deltas;
|
2022-12-09 22:57:22 -08:00
|
|
|
const indices = 20..220 by 40;
|
2022-12-09 22:57:32 -08:00
|
|
|
writeln(+ reduce (states[indices-1] * indices));
|
2022-12-09 22:57:22 -08:00
|
|
|
|
2022-12-09 22:57:32 -08:00
|
|
|
const pixels = [(x, pc) in zip(states[0..<240], 0..)]
|
|
|
|
if abs((pc % 40) - x) <= 1 then "#" else " ";
|
|
|
|
writeln(reshape(pixels, {1..6, 1..40}));
|