diff options
Diffstat (limited to '')
-rw-r--r-- | 2022/day06.awk | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/2022/day06.awk b/2022/day06.awk index 176cd4f..b682780 100644 --- a/2022/day06.awk +++ b/2022/day06.awk @@ -1,5 +1,13 @@ +function repeats(s, i) { + for (i = 1; i <= length(s); i++) { + for (j = i+1; j <= length(s); j++) { + if (substr(s, i, 1) == substr(s, j, 1)) return 1; + } + } + return 0; +} { - for (i = 1; i < length; i++) { + for (i = 1; i <= length; i++) { c1 = c2; c2 = c3; c3 = c4; @@ -11,4 +19,10 @@ print i; break; } + for (i = 1; i+14 <= length; i++) { + s = substr($1, i, 14); + if (repeats(s)) continue; + print 13+i; + break; + } } |