diff options
author | Thomas Voss <mail@thomasvoss.com> | 2022-12-02 16:54:18 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2022-12-02 16:54:18 +0100 |
commit | 093de3f52b0b7dfb7cc42e05c9c4267c7011c001 (patch) | |
tree | 70e1f1764061fdcb96c0f95ad47d4994ca1c26e4 /2016/01 | |
parent | 231b40909b5a3c2e202bcb48ab40e42a4213bdff (diff) |
Add 2016 day 1 solutions
Diffstat (limited to '2016/01')
-rw-r--r-- | 2016/01/.gitignore | 1 | ||||
-rw-r--r-- | 2016/01/Makefile | 1 | ||||
-rw-r--r-- | 2016/01/input | 1 | ||||
-rw-r--r-- | 2016/01/puzzles.awk | 27 |
4 files changed, 30 insertions, 0 deletions
diff --git a/2016/01/.gitignore b/2016/01/.gitignore new file mode 100644 index 0000000..95a78b1 --- /dev/null +++ b/2016/01/.gitignore @@ -0,0 +1 @@ +puzzle-[12].awk diff --git a/2016/01/Makefile b/2016/01/Makefile new file mode 100644 index 0000000..3e0defd --- /dev/null +++ b/2016/01/Makefile @@ -0,0 +1 @@ +include ../../Makefiles/awk.mk diff --git a/2016/01/input b/2016/01/input new file mode 100644 index 0000000..34c0b12 --- /dev/null +++ b/2016/01/input @@ -0,0 +1 @@ +L1, L3, L5, L3, R1, L4, L5, R1, R3, L5, R1, L3, L2, L3, R2, R2, L3, L3, R1, L2, R1, L3, L2, R4, R2, L5, R4, L5, R4, L2, R3, L2, R4, R1, L5, L4, R1, L2, R3, R1, R2, L4, R1, L2, R3, L2, L3, R5, L192, R4, L5, R4, L1, R4, L4, R2, L5, R45, L2, L5, R4, R5, L3, R5, R77, R2, R5, L5, R1, R4, L4, L4, R2, L4, L1, R191, R1, L1, L2, L2, L4, L3, R1, L3, R1, R5, R3, L1, L4, L2, L3, L1, L1, R5, L4, R1, L3, R1, L2, R1, R4, R5, L4, L2, R4, R5, L1, L2, R3, L4, R2, R2, R3, L2, L3, L5, R3, R1, L4, L3, R4, R2, R2, R2, R1, L4, R4, R1, R2, R1, L2, L2, R4, L1, L2, R3, L3, L5, L4, R4, L3, L1, L5, L3, L5, R5, L5, L4, L2, R1, L2, L4, L2, L4, L1, R4, R4, R5, R1, L4, R2, L4, L2, L4, R2, L4, L1, L2, R1, R4, R3, R2, R2, R5, L1, L2 diff --git a/2016/01/puzzles.awk b/2016/01/puzzles.awk new file mode 100644 index 0000000..c20a12a --- /dev/null +++ b/2016/01/puzzles.awk @@ -0,0 +1,27 @@ +#!/usr/bin/gawk -f + +function abs(n) { return n < 0 ? -n : n } + +function move(n) { + # START PART 1 + d == 0 ? y += n : \ + d == 1 ? x += n : \ + d == 2 ? y -= n : \ + x -= n + # END PART 1 START PART 2 + for (i = 1; i <= n; i++) { + d == 0 ? y++ : \ + d == 1 ? x++ : \ + d == 2 ? y-- : \ + x-- + if (map[x, y]++) + exit + } + # END PART 2 +} + +BEGIN { RS = ", "; FPAT = "[LR]|[0-9]+" } +/L/ { if (--d == -1) d = 3 } +/R/ { if (++d == +4) d = 0 } + { move($2) } +END { print abs(x) + abs(y) } |