Cleaned up Chapel solution

This commit is contained in:
Danila Fedorin 2022-12-09 22:57:32 -08:00
parent e26f41cd68
commit 5f2cb7c7ee

View File

@ -1,40 +1,23 @@
use IO, Map; use IO, Map;
iter ops() { iter ops() {
yield 1; // Initial state
for line in stdin.lines().strip() { for line in stdin.lines().strip() {
if line == "noop" then { select line[0..3] {
yield [0]; when "noop" do yield 0;
} else { when "addx" {
const (_, _, n) = line.partition(" "); yield 0;
yield [0, n : int]; yield line[5..] : int;
}
} }
} }
} }
var pc = 1; const deltas = ops();
var reg = 1; const states = + scan deltas;
var state = new map(int, int);
for op in ops() {
writeln(op);
for diff in op {
state[pc] = reg;
reg += diff;
pc += 1;
writeln("State: ", (pc, reg));
}
}
const indices = 20..220 by 40; const indices = 20..220 by 40;
const values = state[indices]; writeln(+ reduce (states[indices-1] * indices));
writeln(indices * values);
writeln(+ reduce (indices * values));
var crt: [1..6, 0..<40] bool = false; const pixels = [(x, pc) in zip(states[0..<240], 0..)]
if abs((pc % 40) - x) <= 1 then "#" else " ";
for (idx, pc) in zip(crt.domain, 1..) { writeln(reshape(pixels, {1..6, 1..40}));
writeln("sprite pos: ", state[pc], " index: ", idx[1]);
crt[idx] = abs(state[pc] - idx[1]) <= 1;
}
for line in crt.domain.dim(0) {
writeln([i in crt[line, ..]] if i then '#' else '.');
}