kernelthread.com

C Shell

The Towers of Hanoi as a C Shell (csh) script.

#! /bin/csh # # The Towers Of Hanoi # csh # Copyright (C) 2000 Amit Singh. All Rights Reserved. # http://hanoi.kernelthread.com # # Last tested on SunOS 5.9 # if ($#argv != 1) then echo "usage: $0 ndisks" exit 1 endif set N = $1 set S = (0 3 1 $N) while ($#S > 0) set p = $S[1]; shift S set t = $S[1]; shift S set f = $S[1]; shift S set n = $S[1]; shift S set l = `expr 6 - $f - $t` set dn = `expr $n - 1` if ($p == 0) then if ($n == 1) then echo "move $f --> $t" else set S = (0 $l $f $dn 1 $t $f $n $S) endif else echo "move $f --> $t" set S = (0 $t $l $dn $S) endif end

Download

hanoi.csh