aboutsummaryrefslogtreecommitdiff
path: root/2022/10/puzzle-1.awk
diff options
context:
space:
mode:
Diffstat (limited to '2022/10/puzzle-1.awk')
-rwxr-xr-x2022/10/puzzle-1.awk8
1 files changed, 8 insertions, 0 deletions
diff --git a/2022/10/puzzle-1.awk b/2022/10/puzzle-1.awk
new file mode 100755
index 0000000..16c684b
--- /dev/null
+++ b/2022/10/puzzle-1.awk
@@ -0,0 +1,8 @@
+#!/usr/bin/awk -f
+
+BEGIN { x = 1 }
+
+{ if ((++c - 20) % 40 == 0) s += c * x }
+/addx/ { if ((++c - 20) % 40 == 0) s += c * x; x += $2 }
+
+END { print s }