aoc-2022/01.awk

19 lines
298 B
Awk

BEGIN {
RS = "\n\n"; FS = "\n"
TOP = 3
toptot = 0
}
{
tot = 0
for (i = 1; i <= NF; i++)
tot += $i
cal[FNR] = tot
}
END {
asort(cal, cal, "@val_num_desc")
for (i = 1; i <=TOP; i++)
toptot += cal[i]
print "elf with most calories has " cal[1] " calories"
print "sum of top 3: " toptot
}