day6, a set kills all
This commit is contained in:
parent
3ec99a8a10
commit
53014651e9
|
@ -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)
|
|
@ -1,4 +1,4 @@
|
|||
{ j=0; # use -vW=4 or 14
|
||||
{ N=0; j=0; # use -vW=4 or 14
|
||||
for (i=1; ; i++) {
|
||||
c = substr($0,i,1);
|
||||
# look backward for a "new j" > j
|
||||
|
|
|
@ -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))
|
Loading…
Reference in New Issue