day 6, AWK solution, small optim
This commit is contained in:
parent
d0a35caa95
commit
76089ce733
|
@ -2,14 +2,14 @@ BEGIN { W = 14 }
|
||||||
{
|
{
|
||||||
for (i=1; i<=length($1); i++) {
|
for (i=1; i<=length($1); i++) {
|
||||||
window = substr($1,i,W)
|
window = substr($1,i,W)
|
||||||
# compare each char of window to all char of window
|
# compare each char of the window to rest of the window
|
||||||
S = 0 # to count match
|
S = 0 # to count match
|
||||||
for (j=1; j<=W; j++) {
|
for (j=1; j<=W; j++) {
|
||||||
for (k=j; k<=W; k++) {
|
for (k=j+1; k<=W; k++) {
|
||||||
S+= (substr(window,j,1) == substr(window,k,1)) ? 1 : 0
|
S+= (substr(window,j,1) == substr(window,k,1)) ? 1 : 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (S == W) { # if each char match only with itsef
|
if (S == 0) { # if each char match only with itsef
|
||||||
print i + W - 1
|
print i + W - 1
|
||||||
next # finish
|
next # finish
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue