aoc2022/d06/exec.awk

17 lines
357 B
Awk
Raw Permalink Normal View History

2024-04-13 21:52:39 +00:00
{ # use -vW=4 or 14
for (i=1; ; i++) {
2022-12-06 19:17:13 +00:00
window = substr($1,i,W)
2022-12-06 19:21:37 +00:00
# compare each char of the window to rest of the window
2022-12-06 19:17:13 +00:00
S = 0 # to count match
2024-04-13 21:52:39 +00:00
for (j=1; j<W; j++) {
2022-12-06 19:21:37 +00:00
for (k=j+1; k<=W; k++) {
2024-04-13 21:52:39 +00:00
N++
2022-12-06 19:17:13 +00:00
S+= (substr(window,j,1) == substr(window,k,1)) ? 1 : 0
}
}
2022-12-06 19:21:37 +00:00
if (S == 0) {
2024-04-13 21:52:39 +00:00
print i + W - 1, "(" N " loops)"
2022-12-06 19:21:37 +00:00
next
2022-12-06 19:17:13 +00:00
}
}
2024-04-13 21:52:39 +00:00
} # O(N*W^2)