Tower of Hanoi

Program: RMhanoi.z80

This is a recent program, inspired by one I wrote for a Diehl programmable calculator, the first machine I ever programmed, back in 1973/4, that I've referred to elsewhere.

In this puzzle, there are 3 posts in a line: "a", "b" and "c" and a number of rings of different widths. At the start, all rings are on one end post ("a"), the smallest (number "1") on top, then the next smallest (number "2") and so on. A ring can be moved from the top of one post to the top of another provided there is not already a smaller ring on the target post. The aim is to move all rings to the other end post ("c"), one move at a time.

The number of rings (n) - from 3 to 9 - is set by the user. The code can be changed easily to accommodate more, but as the number of moves to complete the puzzle is (2**n) -1, it will take 511 moves just to complete the 9 ring puzzle!

The user can opt to complete the puzzle, or have the computer do it. The algorithm used for this latter mode is this one.

The representation is text-based, not graphical, ring locations on posts being displayed in a row as shown in the image above.