[System Requirements|Using Hanoi.lbr|Minimum number of moves|Feedback
No doubt you've seen the Towers of Hanoi puzzle in some shape or form. The object of the puzzle is to move the disks from the starting peg to one of the other two pegs. The rules are simple:
System Requirements & Installation
When you start a new game, Hanoi.lbr asks you how many disks to set up on the first peg. You can have as little as 3 or as many as 7 disks.
Click and hold the mouse on the disk you want to move. When the mouse cursor changes to a hand, you can drag the disk to another peg. The pegs appear momentarily outlined when a disk is in the drop position. You can drop the disk anywhere on the peg. If the drop is a legal move, the disk is automatically positioned on top of the other disks on that peg. If the move is illegal, the disk returns to its original position.
The status bar displays the number of moves you have made so far. Want to know the minimum number of moves?
A congratulatory message pops up when you solve the game. You can also give up by closing the main window.
The Towers of Hanoi menu has three options:
Computing the Minimum Number of Moves
The minimum number of moves required to solve the puzzle for n disks is given by the recurrance relation:
The values can also be computed as
For example, when n = 3, you must first move the top 2 disks to an intermediate peg (Tn-1), then move the 3rd disk to the target peg, and finally move the 2 smaller disks on top of the 3rd disk (Tn-1). The following table shows the minimum number of moves for 1 to 7 disks:
| Disks | Moves |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 7 |
| 4 | 15 |
| 5 | 31 |
| 6 | 63 |
| 7 | 127 |
I hope you find Hanoi.lbr to be entertaining. You may be wondering what compelled me to write it... I was reading a Delphi programming book one evening. One of the examples was a Delphi implementation of the Towers of Hanoi puzzle. I thought "why can't that be done in Omnis?" So I set out to develop an Omnis version of this famous puzzle.
Hanoi.lbr also makes a fun example of using drag-and-drop in Omnis.
Feel free to send any comments, suggestions or bug reports to me at brianos@ziplink.net.
This is a freeware utility. I do not warranty Hanoi in any way, and am not liable for any damages that may occur in its use. Use Hanoi at your own risk. Look both ways before crossing the street. By downloading and using Hanoi.lbr you acknowledge your agreement to these terms.
Back to top of page|Back to my Omnis page|Back to my home page