diff options
author | June McEnroe <june@causal.agency> | 2022-12-01 14:22:44 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2022-12-01 14:22:44 -0500 |
commit | 164e6b0fda3bf792af6ac0d8d2bc30200b805f79 (patch) | |
tree | 87930ccda3460603cdff73040b7a525638e6b671 /2022 | |
parent | Solve day 1 part 1 (diff) | |
download | aoc-164e6b0fda3bf792af6ac0d8d2bc30200b805f79.tar.gz aoc-164e6b0fda3bf792af6ac0d8d2bc30200b805f79.zip |
Solve day 1 part 2
Diffstat (limited to '')
-rw-r--r-- | 2022/day01.awk | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/2022/day01.awk b/2022/day01.awk index c81d624..0fbde52 100644 --- a/2022/day01.awk +++ b/2022/day01.awk @@ -1,10 +1,24 @@ /[[:digit:]]+/ { cals += $1; } -/^$/ { - if (cals > max) max = cals; +function push() { + if (cals > max1) { + max3 = max2; + max2 = max1; + max1 = cals; + } else if (cals > max2) { + max1 = max2; + max2 = cals; + } else if (cals > max3) { + max3 = cals; + } cals = 0; } +/^$/ { + push(); +} END { - print max; + push(); + print max1; + print max1 + max2 + max3; } |