From 01ad8f2353f52c9cb29a744c2de4adda8f33945e Mon Sep 17 00:00:00 2001 From: "matthias@arch" Date: Sat, 3 Dec 2022 01:33:53 +0100 Subject: [PATCH] added task 2 --- 1/day1-1.awk | 1 + 1/day1-2.sh | 2 ++ 2 files changed, 3 insertions(+) create mode 100755 1/day1-1.awk create mode 100755 1/day1-2.sh diff --git a/1/day1-1.awk b/1/day1-1.awk new file mode 100755 index 0000000..7c763d4 --- /dev/null +++ b/1/day1-1.awk @@ -0,0 +1 @@ +BEGIN{sum=0; max_sum=0} {if (NF != 0) {sum+=$1} else {if (sum > max_sum) {max_sum=sum}; sum=0}} END{print max_sum} diff --git a/1/day1-2.sh b/1/day1-2.sh new file mode 100755 index 0000000..6ccd659 --- /dev/null +++ b/1/day1-2.sh @@ -0,0 +1,2 @@ +#!/bin/bash +awk 'BEGIN{sum=0} {if (NF != 0) {sum+=$1} else {print sum; sum=0}}' input.txt | sort -n | tail -n 3 | awk 'BEGIN{sum=0} {sum+=$1} END{print sum}'