aoc2022/d06/exec1.awk

17 lines
362 B
Awk

{ N=0; # use -vW=4 or 14
for (i=1; ; i++) {
window = substr($0,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 (k=j+1; k<=W; k++) {
N++
S+= (substr(window,j,1) == substr(window,k,1)) ? 1 : 0
}
}
if (S == 0) {
print i + W - 1, "(" N " loops)"
next
}
}
} # O(N*W^2)