diff --git a/d06/exec.awk b/d06/exec.awk index 2cd1cb7..4eeae56 100644 --- a/d06/exec.awk +++ b/d06/exec.awk @@ -1,17 +1,17 @@ -BEGIN { W = 14 } -{ - for (i=1; i<=length($1); i++) { +{ # use -vW=4 or 14 + for (i=1; ; i++) { window = substr($1,i,W) # compare each char of the window to rest of the window S = 0 # to count match - for (j=1; j<=W; j++) { + for (j=1; j j + for (k=i-1; k>j; k--) { + N++ + if (substr($0,k,1) == c) { + j = k + break + } + } + if ((i-j) == W) { + print i, "(" N " loops)" + next + } + } +} # O(N*W) \ No newline at end of file