diff --git a/2017/day-02/solution.sh b/2017/day-02/solution.sh index 51517fd..ee62281 100755 --- a/2017/day-02/solution.sh +++ b/2017/day-02/solution.sh @@ -4,13 +4,13 @@ sum1=0 sum2=0 while read -r line; do - sorted=$(echo "$line" | xargs -n 1 echo | sort -n) - ((sum1 += $(echo "$sorted" | tail -n 1) - $(echo "$sorted" | head -n 1))) + sorted=$(tr '\t' '\n' <<< "$line" | sort -n) + ((sum1 += ${sorted##*$'\n'} - ${sorted%%$'\n'*})) for a in $sorted; do for b in $sorted; do if [[ $a -le $b ]]; then - continue + break fi if [[ $((a % b)) -eq 0 ]]; then