day6, a set kills all

This commit is contained in:
setop 2024-04-14 01:16:42 +02:00
parent 3ec99a8a10
commit 53014651e9
3 changed files with 31 additions and 1 deletions

17
d06/exec1.awk Normal file
View File

@ -0,0 +1,17 @@
{ 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)

View File

@ -1,4 +1,4 @@
{ j=0; # use -vW=4 or 14 { N=0; j=0; # use -vW=4 or 14
for (i=1; ; i++) { for (i=1; ; i++) {
c = substr($0,i,1); c = substr($0,i,1);
# look backward for a "new j" > j # look backward for a "new j" > j

13
d06/exec3.awk Normal file
View File

@ -0,0 +1,13 @@
{ # 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))