diff options
Diffstat (limited to '2022/01/puzzle-2.awk')
-rwxr-xr-x | 2022/01/puzzle-2.awk | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/2022/01/puzzle-2.awk b/2022/01/puzzle-2.awk index 6186084..11f46c0 100755 --- a/2022/01/puzzle-2.awk +++ b/2022/01/puzzle-2.awk @@ -1,17 +1,5 @@ -#!/usr/bin/awk -f +#!/usr/bin/gawk -f /[0-9]+/ { acc += $1 } -!/./ { - if (acc > max[1]) { - max[3] = max[2]; - max[2] = max[1]; - max[1] = acc; - } else if (acc > max[2]) { - max[3] = max[2]; - max[2] = acc; - } else if (acc > max[3]) - max[3] = acc; - acc = 0 -} - -END { print max[1] + max[2] + max[3] } +!/./ { max[++i] = acc; acc = 0 } +END { asort(max); print max[i] + max[i - 1] + max[i - 2] } |