aboutsummaryrefslogtreecommitdiff
path: root/2022/10/puzzle-2.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-2.awk
parent603fb558d957201754cc3e64004f83e2f9ff4745 (diff)
Add 2022 day 10 solutions
Diffstat (limited to '2022/10/puzzle-2.awk')
-rwxr-xr-x2022/10/puzzle-2.awk15
1 files changed, 15 insertions, 0 deletions
diff --git a/2022/10/puzzle-2.awk b/2022/10/puzzle-2.awk
new file mode 100755
index 0000000..31a9ea6
--- /dev/null
+++ b/2022/10/puzzle-2.awk
@@ -0,0 +1,15 @@
+#!/usr/bin/awk -f
+
+BEGIN { x = 1 }
+
+{
+ for (i = 0; i < ($1 == "addx" ? 2 : 1); i++) {
+ p = (++c % 40) - 1
+ if (p == -1)
+ p = 39
+ printf (p == x - 1 || p == x || p == x + 1) ? "█" : " "
+ if (p == 39)
+ print ""
+ }
+}
+/addx/ { x += $2 }