From e26f41cd685c2257cbf3dd22fc909fc515a1e1c0 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 9 Dec 2022 22:57:22 -0800 Subject: [PATCH] Initial Chapel solution --- day10.chpl | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 day10.chpl diff --git a/day10.chpl b/day10.chpl new file mode 100644 index 0000000..3294c8e --- /dev/null +++ b/day10.chpl @@ -0,0 +1,40 @@ +use IO, Map; + +iter ops() { + for line in stdin.lines().strip() { + if line == "noop" then { + yield [0]; + } else { + const (_, _, n) = line.partition(" "); + yield [0, n : int]; + } + } +} + +var pc = 1; +var reg = 1; +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 values = state[indices]; +writeln(indices * values); +writeln(+ reduce (indices * values)); + +var crt: [1..6, 0..<40] bool = false; + +for (idx, pc) in zip(crt.domain, 1..) { + 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 '.'); +}