Skip to content

Instantly share code, notes, and snippets.

@jstolle
Created August 2, 2012 20:59
Show Gist options
  • Save jstolle/3240598 to your computer and use it in GitHub Desktop.
Save jstolle/3240598 to your computer and use it in GitHub Desktop.
Marginal Taxes Owed
#!/bin/bash
GROSS=$1
if [[ -z "${GROSS}" ]];then
echo "usage $0 <income>" >&2
exit 1
fi
declare -a BRACKETS=('0 10' '8376 15' '34001 25' '82401 28' '171851 33' '373651 35')
NUM_BRACKETS=$(expr ${#BRACKETS[@]} - 1)
OWED=0
while [[ $NUM_BRACKETS -gt -1 ]];do
AMT=$(echo ${BRACKETS[${NUM_BRACKETS}]} | cut -f 1 -d ' ')
PRCT=$(echo ${BRACKETS[${NUM_BRACKETS}]} | cut -f 2 -d ' ')
if [[ ${GROSS} -gt ${AMT} ]];then
WRKNG=$(echo "float_scale=2; ${GROSS} - ${AMT}" | bc -q 2>/dev/null)
TAX=$(echo "float_scale=2; ${WRKNG} * .${PRCT}" | bc -q 2>/dev/null)
OWED=$(echo "float_scale=2; ${OWED} + ${TAX}" | bc -q 2>/dev/null)
GROSS=${AMT}
fi
NUM_BRACKETS=$(expr ${NUM_BRACKETS} - 1)
done
echo $OWED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment