
//
// This program uses recursion to solve the classic Towers of Hanoi puzzle.
// The user is asked how many disks to move and the program reports a
// series of moves that will solve the puzzle.

public class Tower
{
  
  public static void giveIntro()
       // post: program is explained to the user
  {
    System.out.println("This program solves the Towers of Hanoi puzzle.");
    System.out.println("You specify how many disks to put initially on");
    System.out.println("tower A and I will tell you a series of moves to"); 
    System.out.println("get them all to tower C.");
    System.out.println();
  }

  public static void moveOneDisk(char source, char dest)
       // post: Reports the move of one disk
  {
    System.out.println("Move disk from " + source + " to " + dest);
  }

  public static void moveDisks(int n, char source, char dest, char temp)
       // post: Recursively moves n disks from source to dest using
       //       temp as a temporary.  Base case is moving 1 disk, recursive
       //       case involves moving n - 1 disks to a temporary, then moving
       //       one disk, then moving the n -1 disks from the tempoarary to
       //       the source.
  {
    if (n == 1)
      moveOneDisk(source, dest);
    else {
      moveDisks(n - 1, source, temp, dest);
      moveOneDisk(source, dest);
      moveDisks(n - 1, temp, dest, source);
    }
  }
  
  public static void main(String[] args)
  {
    giveIntro();
    System.out.print("Number of disks? ");
    int numDisks = 3; // try increasing this number, how patient are you?
    				  // why does it take long when this number is large?
    moveDisks(numDisks, 'A', 'C', 'B');
  }

}

