From 25c1ddbeddeda95bb01f211ef25df57262eab3d1 Mon Sep 17 00:00:00 2001 From: setop Date: Tue, 6 Dec 2022 20:00:50 +0100 Subject: [PATCH] day 6, AWK solution --- d06/exec.awk | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 d06/exec.awk diff --git a/d06/exec.awk b/d06/exec.awk new file mode 100644 index 0000000..169f80f --- /dev/null +++ b/d06/exec.awk @@ -0,0 +1,18 @@ +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 each char match only with itsef + if (S == W) { + print i + W - 1 + next # finish + } + } +} \ No newline at end of file