From efa81418eb6c1856cb00cedee0294089ca42fcb2 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 12 Dec 2022 10:16:46 -0800 Subject: [PATCH] Make tweaks to day 10 code to make it clearer --- day10.chpl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/day10.chpl b/day10.chpl index 9e45c22..c791562 100644 --- a/day10.chpl +++ b/day10.chpl @@ -13,11 +13,12 @@ iter ops() { } } -const deltas = ops(); -const states = + scan deltas; -const indices = 20..220 by 40; -writeln(+ reduce (states[indices-1] * indices)); +const deltas = ops(), + cycles = deltas.size, + states: [1..cycles] int = + scan deltas, + interesting = 20..220 by 40; +writeln(+ reduce (states[interesting] * interesting)); -const pixels = [(x, pc) in zip(states[0..<240], 0..)] +const pixels = [(x, pc) in zip(states[1..240], 0..)] if abs((pc % 40) - x) <= 1 then "#" else " "; writeln(reshape(pixels, {1..6, 1..40}));