From 277be4d57c393582bbc39e7c79c25a05684e53e6 Mon Sep 17 00:00:00 2001 From: setop Date: Tue, 6 Dec 2022 20:21:37 +0100 Subject: [PATCH] day 6, AWK solution, small optim --- d06/exec.awk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/d06/exec.awk b/d06/exec.awk index 99ad33c..2cd1cb7 100644 --- a/d06/exec.awk +++ b/d06/exec.awk @@ -2,16 +2,16 @@ 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 + # compare each char of the window to rest of the window S = 0 # to count match for (j=1; j<=W; j++) { - for (k=j; k<=W; k++) { + for (k=j+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 + if (S == 0) { print i + W - 1 - next # finish + next } } } \ No newline at end of file