day 1 awk solution

main
magical 2022-12-01 16:12:18 -08:00
parent 05189aa162
commit 4acdecdeef
1 changed files with 8 additions and 0 deletions

8
day01/sol.sh 100644
View File

@ -0,0 +1,8 @@
# solve day 1 with awk and sort
# part 1
awk 'BEGIN{RS="\n\n";m=0} {t=0; for(i=1;i<=NF;i++)t+=$i; if(m<t)m=t} END{print m}' < input
# part 2
awk 'BEGIN{RS="\n\n"} {t=0; for(i=1;i<=NF;i++)t+=$i; print t}' < input | sort -nr |
awk 'BEGIN{t=0} {t+=$1} NR==3 {print t; quit}'