day 1 awk solution
parent
05189aa162
commit
4acdecdeef
|
@ -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}'
|
Loading…
Reference in New Issue