1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#!/bin/bash
# Towers of Hanoi
init() {
_Dbg_set_trace; : ; :
}
hanoi() {
local -i n=$1
local -r a=$2
local -r b=$3
local -r c=$4
_Dbg_set_trace; : ; :
if (( n > 0 )) ; then
(( n-- ))
hanoi $n $a $c $b
((disc_num=max-n))
echo "Move disk $n on $a to $b"
if (( n > 0 )) ; then
hanoi $n $c $b $a
fi
fi
}
if [[ -n $1 ]] ; then
builddir=$1
elif [[ -z $builddir ]] ; then
builddir=`pwd`/..
fi
source ${builddir}/bashdb-trace -q -L .. -B -x settrace.cmd
typeset -i max=1
init
hanoi $max "a" "b" "c"
_Dbg_set_trace _Dbg_do_quit; : ; :
|