diff options
author | June McEnroe <june@causal.agency> | 2022-12-06 10:34:43 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2022-12-06 10:34:43 -0500 |
commit | f003d2b372fe01a041399fd16dfc956dda46a273 (patch) | |
tree | fb2346b89f0d2d51b9928e73c1a28a54d52f677f /2022 | |
parent | Solve day 6 part 1 (diff) | |
download | aoc-f003d2b372fe01a041399fd16dfc956dda46a273.tar.gz aoc-f003d2b372fe01a041399fd16dfc956dda46a273.zip |
Solve day 6 part 2
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; + } } |