Skip to content

Instantly share code, notes, and snippets.

@codedot
Created March 5, 2012 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codedot/1977362 to your computer and use it in GitHub Desktop.
Save codedot/1977362 to your computer and use it in GitHub Desktop.
Pouring Tanks (reverse)
alexo@codedot:~/Documents/Projects/bc$ cat reverse.sh
l=$1
r=$2
n=$3
shift
shift
shift
. pour.sh 2>&-
echo "$script s($l, $r, -1, 0)" | bc >left.tmp
echo "$script s($l, $r, -1, 1)" | bc >right.tmp
left=`head -n$n left.tmp | tail -n1 | sed 's/[^0-9]*//'`
right=`head -n$n right.tmp | tail -n1 | sed 's/[^0-9]*//'`
if sh pour.sh $l $r $left | grep -q "#$n"; then
echo $left
elif sh pour.sh $l $r $right | grep -q "#$n"; then
echo $right
else
echo None
fi
rm -f {left,right}.tmp
alexo@codedot:~/Documents/Projects/bc$ sh reverse.sh 1010 1011 2012
507
alexo@codedot:~/Documents/Projects/bc$ sh reverse.sh 1010 1011 2011
None
alexo@codedot:~/Documents/Projects/bc$ sh reverse.sh 1010 1011 2010
503
alexo@codedot:~/Documents/Projects/bc$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment