19 lines
331 B
Awk
19 lines
331 B
Awk
|
# Pure awk solution for day 1
|
||
|
|
||
|
# run me with: awk -f sol.awk <input
|
||
|
|
||
|
function insert(v) {
|
||
|
for(i=1;i<=3&&a[i]<v;i++) {
|
||
|
a[i-1]=a[i];
|
||
|
a[i]=v;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
BEGIN { RS="\n\n" }
|
||
|
|
||
|
{ t=0; for(i=1;i<=NF;i++) t+=$i; insert(t) }
|
||
|
|
||
|
END { print a[3] } # part 1
|
||
|
|
||
|
END { t=0; for(i=1;i<=3;i++) t+=a[i]; print t } # part 2
|