aoc2022/d06/exec3.awk

13 lines
227 B
Awk
Raw Normal View History

2024-04-13 23:16:42 +00:00
{ # use -vW=4 or 14
for (i=1; ; i++) {
window = substr($0,i,W)
for (j=1; j<=W; j++) { # populate a Set
A[substr(window,j,1)]=1
}
if (length(A) == W) {
print i + W - 1
next
}
delete A
}
} # O(N*W*log2(W))