AdventOfCode-2022/day10.chpl

25 lines
566 B
Chapel
Raw Normal View History

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
}
}
}
const deltas = ops(),
cycles = deltas.size,
states: [1..cycles] int = + scan deltas,
interesting = 20..220 by 40;
writeln(+ reduce (states[interesting] * interesting));
2022-12-09 22:57:22 -08:00
const pixels = [(x, pc) in zip(states[1..240], 0..)]
2022-12-09 22:57:32 -08:00
if abs((pc % 40) - x) <= 1 then "#" else " ";
writeln(reshape(pixels, {1..6, 1..40}));