about summary refs log tree commit diff
path: root/aoc/2022/10/part-one.awk
diff options
context:
space:
mode:
Diffstat (limited to 'aoc/2022/10/part-one.awk')
-rwxr-xr-xaoc/2022/10/part-one.awk8
1 files changed, 8 insertions, 0 deletions
diff --git a/aoc/2022/10/part-one.awk b/aoc/2022/10/part-one.awk
new file mode 100755
index 0000000..756464e
--- /dev/null
+++ b/aoc/2022/10/part-one.awk
@@ -0,0 +1,8 @@
+#!/usr/bin/env -S awk -f
+BEGIN { cycle = x = 1 }
+{ cycle++ }
+cycle % 40 == 20 { strength += cycle * x }
+{ x += $2 }
+/^addx/ { cycle++ }
+/^addx/ && cycle % 40 == 20 { strength += cycle * x }
+END { print strength }