From d0a35caa957528143a199ef6083ce8a1f4f6a326 Mon Sep 17 00:00:00 2001 From: setop Date: Tue, 6 Dec 2022 20:17:13 +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..99ad33c --- /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=j; 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