summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-12-11 11:53:32 -0500
committerJune McEnroe <june@causal.agency>2022-12-11 11:55:38 -0500
commit89806e577276de9c544bc423424872b2efc99258 (patch)
tree5d7ac799216ef12af52cf46c9e5f353176095571
parentSolve day 9 part 2 (diff)
downloadaoc-89806e577276de9c544bc423424872b2efc99258.tar.gz
aoc-89806e577276de9c544bc423424872b2efc99258.zip
Solve day 10 part 1
-rw-r--r--2022/day10.awk21
1 files changed, 21 insertions, 0 deletions
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;
+}