aboutsummaryrefslogtreecommitdiff
path: root/2022/10/puzzle-1.awk
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2022-12-11 23:27:34 +0100
committerThomas Voss <mail@thomasvoss.com> 2022-12-11 23:27:34 +0100
commitfbee8c65aa88b94e97b2cb6b29f615859bf34660 (patch)
treefe9dba897bc91cb12ceb20f5ba56a8a4f0c9dd8f /2022/10/puzzle-1.awk
parent603fb558d957201754cc3e64004f83e2f9ff4745 (diff)
Add 2022 day 10 solutions
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 }