day 1 pure awk solution

main
magical 2022-12-01 18:20:17 -08:00
parent 4acdecdeef
commit 5a7bf9b365
1 changed files with 18 additions and 0 deletions

18
day01/sol.awk 100644
View File

@ -0,0 +1,18 @@
# 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