Skip to content

Instantly share code, notes, and snippets.

@grahamc
Forked from anonymous/tmp.sh
Created January 1, 2013 02:53
Show Gist options
  • Save grahamc/4424944 to your computer and use it in GitHub Desktop.
Save grahamc/4424944 to your computer and use it in GitHub Desktop.
#!/bin/bash
bottle=12.5
empty=0.95
s=6.95
i=1
tabspace=" "
defmax=5
if [ -z $1 ]; then
max=$defmax
else
max=$1
fi
while [[ $i -lt $max ]]; do
total=`echo "($i * ($bottle + $empty)) + $s" | bc -l`
if [[ $i -ge 5 ]]; then
total=`echo "$total * .95"|bc -l`
fi
echo "Bottles: $i"
echo "${tabspace}Total: $total"
echo -n "${tabspace}Cost per oz: "
echo "$total / (3 * $i)" | bc -l
half=`echo $total / 2 | bc -l`
echo "${tabspace}50%: $half"
i=$(($i+1))
done
@grahamc
Copy link
Author

grahamc commented Jan 1, 2013

Output:

Bottles: 1
  Total: 20.40
  Cost per oz: 6.80000000000000000000
  50%: 10.20000000000000000000
Bottles: 2
  Total: 33.85
  Cost per oz: 5.64166666666666666666
  50%: 16.92500000000000000000
Bottles: 3
  Total: 47.30
  Cost per oz: 5.25555555555555555555
  50%: 23.65000000000000000000
Bottles: 4
  Total: 60.75
  Cost per oz: 5.06250000000000000000
  50%: 30.37500000000000000000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment