summary refs log tree commit diff homepage
path: root/2022
diff options
context:
space:
mode:
Diffstat (limited to '2022')
-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;
+}