#!/bin/bash [[ $6 ]] || { echo "needs 6 args"; exit 1; } case "$1" in elf) units=elves costs=( 21 16 6 0 194 ) ;; cyc) units=cyclopses costs=( 35 69 27 9 595 ) ;; *) echo "unknown unit type" exit 2 ;; esac g1=$(( 5*$2 + 5*$3 + 10*$4 + 10*$5 )) g=$(( g1 + $6 )) n1=$(( 5*costs[0] + 5*costs[1] + 10*costs[2] + 10*costs[3] )) n=$(( n1 + costs[4] )) i1=$((g/n)) i2=$((g1/n1)) i=$(( i1 < i2 ? i1 : i2 )) echo "$((i*costs[0])) lumber, $((i*costs[1])) ore, $((i*costs[2])) sulfur, $((i*costs[3])) crystal, $((i*costs[4])) gold" echo " makes $i ${units}"