From f1ae64244113a6a849744ab951160af8c19eb8c6 Mon Sep 17 00:00:00 2001 From: setop Date: Tue, 6 Dec 2022 20:15:16 +0100 Subject: [PATCH] day 6, AWK solution --- d06/exec.awk | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 d06/exec.awk diff --git a/d06/exec.awk b/d06/exec.awk new file mode 100644 index 0000000..24ab777 --- /dev/null +++ b/d06/exec.awk @@ -0,0 +1,17 @@ +BEGIN { W = 14 } +{ + for (i=1; i<=length($1); i++) { + window = substr($1,i,W) + # compare each char of window to all char of window + S = 0 # to count match + for (j=1; j<=W; j++) { + for (k=1; k<=W; k++) { + S+= (substr(window,j,1) == substr(window,k,1)) ? 1 : 0 + } + } + if (S == W) { # if each char match only with itsef + print i + W - 1 + next # finish + } + } +} \ No newline at end of file