kernelthread.com

Hanoimania!

What?

This page contains my various (over a hundred) implementations of the Towers of Hanoi problem, or rather, its solution. Some of these are understandably weird. While some differ in the "programming language" (loosely speaking) of implementation (there's one in LOGO, for example), there are many others that differ in concept.

Such As?

Consider the Hanoi OS. This is an x86-bootable operating system that solves the Hanoi puzzle as its primary task. Then there are implementations of Hanoi running on embedded systems. There is an animated Hanoi for the Sega Dreamcast Game Console (dreamcast-hanoi). There is one for the Nintendo Gameboy Advance (gameboy-hanoi). There also are implementations of Hanoi as a loadable kernel module for Linux (lkm-linux-hanoi), a system call for FreeBSD (lkm-bsd-hanoi), one that runs on a car MP3 player (empeg-hanoi), one as a ping server that can send you Hanoi moves as ICMP echo response sequence numbers if you ping it, and write-only monstrosities such as the following sed script:

s~^xx*$~:n:3:2:1:&:~;tB;d;:B;/^:$/d;h s~^:.:\(.\):.:\(.\):*:.*~\2 --> \1~;x /^:y:.:.:.:*:.*/b0;/^:n:.:.:.:x:.*/b1 s~:n:\(.\):\(.\):\(.:x*\)x:\(.*\)~:n:\2:\1:\3:y:\1:\2:\3x:\4~ bB;:1;x;p;x;s~^:n:.:.:.:x:\(.*\)~:\1~;bB;:0;x;p;x s~^:y:\(.\):\(.\):\(.\):x\(x*:*\)~:n:\1:\3:\2:\4~ bB

You can save the above script to a file and try "echo xxx | sed -f filename". Some sed implementations, like the one on some versions of Solaris, might choke on the above because of trailing text after labels. In that case try this differently formatted version. Here is a version with no newlines.

Why?

I am often asked that since I do all this, whether I have a lot of free time on my hands. Between my work and my interests (both of which overlap to a great extent), I actually have no free time. As an aside, I would not (and should not) be expected to "know" so many programming languages, and I don't think I do. However, knowing a computer language is a rather fuzzy idea. If one could write a useful (loosely speaking, again) program in a given language, it is instructive to question whether one knows it.

It is ironical (yes, there is such a word) that the bigger challenge lies not in writing programs in all these different languages and ways, but in rapidly setting up the respective compiler systems and/or development environments on an appropriate platform/operating system. Sometimes compilers, interpreters and other such software for a particular language may be readily available, and run "out of the box", but many times this is not the case. Sometimes it turns out to be a non-trivial problem to get a compiler to function (pun unintended). Of course, once you get past this, you do have to understand some subset of the language!

FAQ

If you have a comment, question or any other feedback, please check the FAQ first to see if I have responded to a similar question already.

Download

You can download all Hanoi implementations as a single archive (gzipped tar file), or browse and download individual implementations as listed below.

The Implementations

Name G R
A+ (an APL) N Y
ABC N N
Ada N Y
Aleph N Y
Algol-60 N Y
Apache Module in C N Y
Apache Module in Perl N Y
AppleScript N Y
Assembly (i1600) Y Y
Assembly (MIPS) N N
Assembly (SPARC) N Y
Assembly (x86) N N
Autoconf N Y
AWK N N
bash N Y
bash Dynamically Loadable Module N Y
BASIC N N
bc Calculator N Y
BCPL N Y
BlooP N Y
Boil N Y
Brain N Y
C# N Y
C N Y
C++ N N
Calc N Y
CGI Script N Y
CLAIRE N Y
COBOL N N
Common Lisp N Y
csh N N
dc (Unix Desk Calculator) N N
Dreamcast Game Console Y Y
Extensible Firmware Interface (EFI) N Y
Empeg (Rio Car MP3 Player) Y Y
Erlang N N
es (Extensible Shell) N N
Euler N Y
FlexLM N Y
Focal N N
FORTH N Y
Gameboy Advance Hand-held Y Y
FORTRAN 90 N Y
Haskell N Y
Icon N Y
Java N Y
Java Applet Y Y
Javascript N Y
K N Y
Kernel Module (FreeBSD) N Y
Kernel Module (Linux) N Y
Kernel Module (Solaris) N Y
ksh N Y
Limbo N Y
LOGO N N
Lua N Y
m4 N Y
Makefile N Y
MATLAB N Y
ML N Y
Mozart N Y
Multiple Languages N Y
Oberon N Y
Objective-C N N
OCaml N Y
OpenBOOT PROM (Sun) N Y
Open Firmware (Macintosh) N Y
Open Firmware (Macintosh, Graphical) Y N
Operating System Hanoi (x86 native) N N
Operating System Hanoi (Flux OS Toolkit) N Y
Operating System Hanoi (SPARC native) N N
Parrot VM Assembly N Y
PASCAL N Y
Perl N Y
Perl (ASCII graphics) Y N
Perl (non-recursive) N N
Perl/Tk Y Y
Perl Extension (XS) in C N Y
PHP N Y
Ping (ICMP) N N
PL/I N Y
Postscript N Y
Prolog N Y
Python N Y
Python Loadable Extension in C N Y
rc N N
Rebol N Y
REXX N Y
Ruby N Y
Sather N Y
Scheme N Y
sed N N
Sendmail N Y
Simula N Y
Smalltalk N Y
SOAP::Lite Web Service N Y
Solaris /proc Hanoi N N
Solaris STREAMS Hanoi N N
Tcl N Y
TCP/IP Server N Y
TEX N Y
troff N Y
VBScript N Y
WebL N Y
Web Service (.NET) N Y
Xlib Y Y
Yacas N Y
Yoix N Y
Yorick N Y
zsh N Y
zsh Dynamically Loadable Builtin N Y

111 Hanoi implementations total. Source unavailable for 4.

Legend

Y Implementation is graphical and/or animated.
N Implementation does not use explicit recursion.