about summary refs log tree commit diff
path: root/aoc/2022/10/part-two.awk
diff options
context:
space:
mode:
Diffstat (limited to 'aoc/2022/10/part-two.awk')
-rwxr-xr-xaoc/2022/10/part-two.awk10
1 files changed, 10 insertions, 0 deletions
diff --git a/aoc/2022/10/part-two.awk b/aoc/2022/10/part-two.awk
new file mode 100755
index 0000000..9126306
--- /dev/null
+++ b/aoc/2022/10/part-two.awk
@@ -0,0 +1,10 @@
+#!/usr/bin/env -S awk -f
+function cycle (c, x) {
+  printf x - 2 < c && c < x + 2 ? "#" : "."
+  printf c == 39 ? "\n" : ""
+  return (c + 1) % 40
+}
+BEGIN { x = 1 }
+{ c = cycle(c, x) }
+/^addx/ { c = cycle(c, x) }
+{ x += $2 }