aboutsummaryrefslogtreecommitdiff
path: root/2022/06/puzzles.awk
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2022-12-06 21:18:25 +0100
committerThomas Voss <mail@thomasvoss.com> 2022-12-06 21:24:49 +0100
commitf17c587b737af0ae44427334dadff51dd84093f7 (patch)
tree10d6ff8046f190c1efc04e5aea09f86c778ca850 /2022/06/puzzles.awk
parent86071ef703bd3e3cd55a4ca93668d157d1941363 (diff)
Add 2022 day 6 solutions
Diffstat (limited to '2022/06/puzzles.awk')
-rw-r--r--2022/06/puzzles.awk26
1 files changed, 26 insertions, 0 deletions
diff --git a/2022/06/puzzles.awk b/2022/06/puzzles.awk
new file mode 100644
index 0000000..2a53949
--- /dev/null
+++ b/2022/06/puzzles.awk
@@ -0,0 +1,26 @@
+#!/usr/bin/gawk -f
+
+BEGIN {
+ RS = "[a-z]"
+ # START PART 1
+ COUNT = 4
+ # END PART 1 START PART 2
+ COUNT = 14
+ # END PART 2
+}
+NR > COUNT {
+ for (i = 2; i <= length(a); i++)
+ a[i - 1] = a[i]
+ delete a[length(a)]
+}
+{ a[(NR == 1 ? 0 : length(a)) + 1] = RT }
+NR > COUNT {
+ for (i in a) {
+ if (_a[a[i]]++ == 1) {
+ delete _a
+ next
+ }
+ }
+ print NR
+ exit
+}