5 filename="${1:-example.txt}"
14 crabs=($(sort -n <<<"${crabs[*]}"))
16 count=$((${#crabs[@]}))
18 for elem in "${crabs[@]}"; do
21 mean=$((total / $count))
25 # Actual best position could be mean +- 1, so loop through them to check
26 for (( tempmean=$((mean-1)); tempmean<=$((mean+1)); tempmean++ )); do
28 for (( a=0; a<${#crabs[@]}; a++ )); do
29 diff=$((tempmean-${crabs[$a]}))
31 if [ $diff -gt 0 ]; then
32 for (( i=0; i<=$diff; i++ )); do
37 if [ $fuel -eq 0 ] || [ $new_fuel -lt $fuel ]; then
43 echo "Found mean: $found_mean"
44 echo "Fuel needed: $fuel"