Hanoi requires a browser with JavaScript support (or NewtonScript support, i.e., Newt's Cape on 2.x Newton with i:General:NewtonScript:Compile preference); besides Newt's Cape, it has been tested with
If Images are not loaded automatically, you'll have to Load/Show Images manually after (re)loading page. Let me know about your experience with other browsers.
What is Tower of Hanoi? | Using Hanoi | Example | Versions | Distribution
In the classic "Tower of Hanoi" game/puzzle, a stack of disks, sorted by size, appears (on the left). You must move these to another stack (on the right) one at a time.
However, you cannot place a larger disk on top of a smaller one, so you must move disks temporarily to another stack.
based on n Disks, total expected moves until solution: 2n-1
displays the current number of moves
choose a number (2-14) based upon selected Speed and your patience. It updates "Moves". Note: if you have image loading disabled, you will have to do an explicit Load/Show Images
Use this to reset stack to left. For jump and move methods, this starts solving; for MSIE, button changes to Stop.
Hanoi is a good example of "recursion" (even though the actual underlying algorithm is implemented iteratively for better process control).
With the situation of 3 disks starting on left stack: If you knew how to move the top 2 disks somewhere else, e.g., to the middle stack, [steps 1-3 below], all you would have to do then is move the bottom disk to the right [step 4]; and since you already know how to move 2 disks, just move those from middle to right [steps 5-7].
Here are step-by-step directions for 3 disks (#1 refers to smallest disk) and 3 stacks (left,middle,right):
You can watch the program do this by setting method to Move and Speed to Slow.
I saw an InterLisp-D version of Tower of Hanoi in late 70s at Xerox PARC. The "classical" version uses a recursive algorithm; the iterative version (which more easily supports Stop) is based on some Scheme code posted by Stancu Radu.
Last updated: 21 Jun 2005: updated syntax via JSLint and tested with newer browsers
This version is free, and can be downloaded locally and mirrored in its entirety. If you copy/modify/improve the code, I would appreciate an acknowledgment of this version and link to this page.
© 1999-2007, S. Weyer. All Rights Reserved Worldwide.