aboutsummaryrefslogtreecommitdiff
path: root/2021/13/puzzles.awk
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2021-12-13 09:57:23 +0100
committerThomas Voss <thomasvoss@live.com> 2021-12-13 09:57:23 +0100
commitaa20de37c060ca31b99c6fc201eb0867d2f5e582 (patch)
tree35a26c511c4a8796b93b6aa7d301533e0cb1c995 /2021/13/puzzles.awk
parent8b2de23eaa431c7d640b73e34cbaa6da66c27da6 (diff)
Add day 13 solutions
Diffstat (limited to '2021/13/puzzles.awk')
-rw-r--r--2021/13/puzzles.awk52
1 files changed, 52 insertions, 0 deletions
diff --git a/2021/13/puzzles.awk b/2021/13/puzzles.awk
new file mode 100644
index 0000000..2450eab
--- /dev/null
+++ b/2021/13/puzzles.awk
@@ -0,0 +1,52 @@
+#!/usr/bin/env -S awk -f
+
+BEGIN { FS = ",|=" }
+/[0-9]+,[0-9]+/ { grid[$2][$1] = 1 }
+
+# START PART 1
+flag == 1 { next }
+# END PART 1
+
+/x/ {
+ for (y in grid) {
+ for (x in grid[y]) {
+ if (x * 1 > $2) {
+ delete grid[y][x]
+ grid[y][$2 - (x - $2)] = 1
+ }
+ }
+ }
+ # START PART 1
+ flag = 1
+ # END PART 1
+}
+
+/y/ {
+ for (y in grid) {
+ if (y * 1 > $2) {
+ for (x in grid[y]) {
+ delete grid[y][x]
+ grid[$2 - (y - $2)][x] = 1
+ }
+ }
+ }
+ # START PART 1
+ flag = 1
+ # END PART 1
+}
+
+END {
+ # START PART 1
+ for (y in grid) {
+ for (x in grid[y])
+ acc += grid[y][x]
+ }
+ print acc
+ # END PART 1 START PART 2
+ for (y = 0; y < 6; y++) {
+ for (x = 0; x < 29; x++)
+ printf grid[y][x] ? "█" : " "
+ print ""
+ }
+ # END PART 2
+}