es - Extensible Shell
The Towers of Hanoi as an es (Extensible Shell) script.
es is a Unix shell written by Byron Rakitzis and Paul Haahr, and is derived from rc. Es has real functions, closures, exceptions and lets you redefine most internal shell operations.
#! /usr/local/bin/es
#
# The Towers Of Hanoi
# es - extensible shell (non-recursive)
# Copyright (C) 2001 Amit Singh. All Rights Reserved.
# http://hanoi.kernelthread.com
#
# Last tested under es-0.9-beta1
#
fn movedisk {
echo $1 ' --> ' $2
}
fn _hanoi {
S = (0 3 1 $1)
while {!~ () $S} {
(p t f n S) = $S
l = `{ expr 6 - $f - $t };
dn = `{ expr $n - 1 };
if {~ 0 $p} {
if {~ 1 $n} {
movedisk $f $t
} {
S = (0 $l $f $dn 1 $t $f $n $S)
}
} {
movedisk $f $t
S = (0 $t $l $dn $S)
}
}
}
fn usage {
throw error echo usage: $1 ndisks
}
if {!~ $#* 1} {
usage $0
}
_hanoi $1
# __END__