Created
December 2, 2022 02:06
-
-
Save tom-henderson/ab3151fd03c9ba1417000199ababad6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
totals=() | |
while read -r item; do | |
cal=$((cal + item)) | |
if [ -z "$item" ]; then | |
totals+=($cal) | |
cal=0 | |
fi | |
done < input | |
totals+=($cal) | |
IFS=$'\n' | |
echo "Max is $(echo "${totals[*]}" | sort -nr | head -n1)" | |
total=0 | |
while read -r n; do | |
total=$((total + n)) | |
done < <(echo "${totals[*]}" | sort -nr | head -n3) | |
echo "Total for top 3 is $total" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment