day 6, AWK solution

This commit is contained in:
setop 2022-12-06 20:00:50 +01:00
parent d34efaa5d1
commit 25c1ddbedd
1 changed files with 18 additions and 0 deletions

18
d06/exec.awk Normal file
View File

@ -0,0 +1,18 @@
BEGIN { W = 14 }
{
for (i=1; i<=length($1); i++) {
window = substr($1,i,W)
# compare each char of window to all char of window
S = 0 # to count match
for (j=1; j<=W; j++) {
for (k=1; k<=W; k++) {
S+= (substr(window,j,1) == substr(window,k,1)) ? 1 : 0
}
}
# if each char match only with itsef
if (S == W) {
print i + W - 1
next # finish
}
}
}