{ j=0; # use -vW=4 or 14 for (i=1; ; i++) { c = substr($0,i,1); # look backward for a "new j" > j for (k=i-1; k>j; k--) { N++ if (substr($0,k,1) == c) { j = k break } } if ((i-j) == W) { print i, "(" N " loops)" next } } } # O(N^2)