Follow Slashdot blog updates by subscribing to our blog RSS feed


Forgot your password?
PC Games (Games) Programming IT Technology

108 Ways To Do The Towers of Hanoi 192

hlarwood74 writes "While it is common to program in a few different languages, somebody has written "towers of hanoi" in 108 different ways, most of them in different programming languages. It's not just the number of languages though ... there are many neat implementations and in some cases he's come up with some strange ways of solving hanoi such as this: "you ping the hanoi machine with the number of disks encoded in the type of service field, and you get response packets whose sequence numbers represent the disk moves need to solve the puzzle". I wanted to ask "why" but the title of the page (hanoimania) explains a few things :)"
This discussion has been archived. No new comments can be posted.

108 Ways To Do The Towers of Hanoi

Comments Filter:
  • Reminds me of... (Score:4, Insightful)

    by zhenlin ( 722930 ) on Monday December 08, 2003 @08:15AM (#7658659)

    The Hello World page.

    The difference? The examples on the Hello World page all have source code. Hanoimania... Not so.

    But.... solving the Towers of Hanoi shows a lot more of the programming environment than Hello World does... Conditionals, branching, recursion, function calls...
  • by mo26101 ( 518770 ) on Monday December 08, 2003 @08:41AM (#7658750)
    This is useful to him, RTFA.
    In fact, while this has gone to an extream, a many developers have a pet progam they implement anytime they run across a new language/platform. This give the programmer a familiar program to implement in an unfamiliar environment. A great way to get your feet wet with something new. Whenever I start working with a new language or on a new platform, I have a game I implement that covers many of the basic program constructs. By the time I have finished the game I have a good enough working knowledge of teh new language and/or platform to begin some real work.

    Here is the same basic explination from the web page (I am assuming it will get slashdotted soon):

    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, I do believe that 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, at least in my opinion, 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!
  • Haskell? (Score:4, Insightful)

    by mattr ( 78516 ) <mattr&telebody,com> on Monday December 08, 2003 @08:43AM (#7658761) Homepage Journal
    Is it just me or does the Haskell one seem to have inverted parameters wrt the vanilla Perl one? Not that I know Haskell.. I was hoping to see some lexical wierdness in Perl and some lambdas and arrows all hanging out for the Haskell one. And wha-hey no smalltalk? well the world goes on..

    Neat idea, I like to see how things are done in other languages. It would be an interesting and intuitive way to show people what other languages are like, a list of programs the same in each language, plus commentary about the highlights of the language that are used.
  • by ComaVN ( 325750 ) on Monday December 08, 2003 @08:54AM (#7658801)
    Of course, a mathematician can solve the puzzle in 5 minutes. He proves the algorithm will solve the puzzle in the end, and leaves the actual moving of the stones as an exercise for his readers.

    He then goes on to generalize the algorithm to support n-dimensional stacks.
  • by OttoM ( 467655 ) on Monday December 08, 2003 @12:43PM (#7660222)
    This solution I always liked best:

    Imagine the disk are in a cricle. Repeat:

    1. move the smallest disk one step clockwise
    2. do the only legal move not involving the smallest disk
    Much easier to remember and perform by hand than the various iterative C programs posted. The proof that it works is left as an exercise to the reader...

Think of it! With VLSI we can pack 100 ENIACs in 1 sq. cm.!