This program plays the Tower of Hanoi puzzle in TEXT mode,
and illustrates recursive programming on the TI-85.


This program shows and solves the well-known Tower of
Hanoi puzzle in a TEXT mode.  For graphic mode, see
the companion program group TwGHanoi.85g

There are two parts; TwrHanoi and suHanMv.  The first sets
up the game, the second is a recursive subroutine to move
the disks.

The Tower of Hanoi puzzle is as follows:  There are three
vertical pegs, usually attached to a board.  On the middle
peg are stacked several disks of decreasing radius (of 
course each disk has a hole in its center for the peg):


      |            |            |
      |           -|-           |      >A tower of Hanoi
      |          --|--          |      >puzzle with 5
      |         ---|---         |      >disks.
      |        ----|----        |
      |       -----|-----       |
#########################################

The object is simple:  move the tower of disks to another 
peg, given two restrictions:  a) You may only move ONE disk
at a time, i.e. only one disk may be un-pegged at any time,
and b) you may never put a larger disk atop a smaller one.

This problem is often used in introductory math or computing
courses to illustrate recursion (why this is so is left as
an exercise; watch how the program solves the problem).

When the program is run, it asks for the number of disks 
you wish to start with (up to 9), and how long you want it
to take to move each disk (minimum of .63 sec).  The latter
is useful to slow the program down for careful observation.
The program then simulates the three pegs with three horiz-
ontal lines of text, with numbers to show the size of the 
disk as shown below:

*
*987654321
*

After a brief delay, the numbers move from row to row, one
at a time, with each row always kept in decreasing order.

Programming notes: The list H keeps track of how "tall" each 
row is.  The matrix "Disk" keeps track of what number/disk
is in which position.
	The TI-85 will allow recursive program calls and
correctly maintains the program's flow of control, but 
does not allow for local variables.  To simulate local vari-
ables, we use the lists FR, TO, and N.

The real variable D keeps track of the depth of recursion we
are currently at; at level D, we move N(D) disks from peg
FR(D) to peg TO(D).  Each time the subroutine is called re-
cursively, D is incremented.  Each time a subroutine ter-
minates, D is decremented.

Written by Prof. Mark Janeba
Dept. of Math
Willamette University
Salem, OR 97301
e-mail: mjaneba@willamette.edu

