From 89806e577276de9c544bc423424872b2efc99258 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 11 Dec 2022 11:53:32 -0500 Subject: Solve day 10 part 1 --- 2022/day10.awk | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 2022/day10.awk diff --git a/2022/day10.awk b/2022/day10.awk new file mode 100644 index 0000000..7788b17 --- /dev/null +++ b/2022/day10.awk @@ -0,0 +1,21 @@ +BEGIN { + cycles = 1; + X = 1; +} +function cycle() { + if (cycles == 20 || (cycles-20) % 40 == 0) { + sum += cycles * X; + } + cycles++; +} +/addx/ { + cycle(); + cycle(); + X += $2; +} +/noop/ { + cycle(); +} +END { + print sum; +} -- cgit 1.4.1