bc Calculator
The Towers of Hanoi as a script for the bc Calculator tool on UNIX.
bc is a language that supports arbitrary precision numbers with interactive execution of statements. More details are available at the GNU bc home page.
/*
* The Towers Of Hanoi
* bc
* Copyright (C) 1998 Amit Singh. All Rights Reserved.
* http://hanoi.kernelthread.com
*
* Tested under GNU bc 1.04
*/
define moveit(i, j) {
print "move "
print i
print " --> "
print j
print "\n"
}
define dohanoi(n, h, d, o) {
if (n > 0) {
silence = dohanoi(n-1, h, o, d)
silence = moveit(h, d)
silence = dohanoi(n-1, o, d, h)
}
}
define hanoi(n) {
silence = dohanoi(n, 1, 3, 2)
}