diff options
author | June McEnroe <june@causal.agency> | 2022-12-04 18:11:07 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2022-12-04 18:11:07 -0500 |
commit | 90b5fac738d0e6e7ce6f7fa83725817d06c3f352 (patch) | |
tree | 148a2de5595efbbedbe619785d23ee6c6a1c61f9 | |
parent | Solve day 3 part 1 (diff) | |
download | aoc-90b5fac738d0e6e7ce6f7fa83725817d06c3f352.tar.gz aoc-90b5fac738d0e6e7ce6f7fa83725817d06c3f352.zip |
Solve day 3 part 2
Diffstat (limited to '')
-rw-r--r-- | 2022/day03.awk | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/2022/day03.awk b/2022/day03.awk index 6a4a153..8a48d69 100644 --- a/2022/day03.awk +++ b/2022/day03.awk @@ -4,14 +4,27 @@ function common(a, b) { if (index(b, as[i])) return as[i]; } } +function common3(a, b, c) { + split(a, as, ""); + for (i in as) { + if (index(b, as[i]) && index(c, as[i])) return as[i]; + } +} function priority(x) { return index("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", x); } { a = substr($1, 1, length($1)/2); b = substr($1, length($1)/2 + 1); - sum += priority(common(a, b)); + sum1 += priority(common(a, b)); + g1 = g2; + g2 = g3; + g3 = $1; + if (NR % 3 == 0) { + sum2 += priority(common3(g1, g2, g3)); + } } END { - print sum; + print sum1; + print sum2; } |