day 1 pure awk solution
This commit is contained in:
parent
4acdecdeef
commit
5a7bf9b365
18
day01/sol.awk
Normal file
18
day01/sol.awk
Normal 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
|
Loading…
x
Reference in New Issue
Block a user