kernelthread.com

Korn Shell

The Towers of Hanoi as a Korn Shell script.

#! /bin/ksh # # The Towers Of Hanoi # Korn Shell # Copyright (C) 2001 Amit Singh. All Rights Reserved. # http://hanoi.kernelthread.com # # Last tested on SunOS 5.9 # function movedisk { echo "move $1 --> $2" } function _hanoi # n f u t { typeset n=$1 typeset f=$2 typeset u=$3 typeset t=$4 if [[ $n < 1 ]] then return else typeset n=`expr $n - 1` _hanoi $n $f $t $u movedisk $f $t _hanoi $n $u $f $t fi } function hanoi # n { _hanoi $1 1 2 3 } if [[ $1 < 0 ]] then echo "usage: $0 ndisks" exit 1 else hanoi $1 fi

Download

hanoi.ksh