// Exercise4_10.java: Find the number of moves for the
// Towers of Hanoi problem
public class Exercise4_10
{
  public static void main (String args[])
  {
    //read number of disks, n
    System.out.println("Enter number of disks");
    int n = MyInput.readInt();
    System.out.println("The moves are:");
    int numOfMoves = moveDisks(n, 'A', 'B', 'C');
    System.out.println("The nuber of moves is "+numOfMoves);
  }

  public static int moveDisks(int n, char fromTower, char toTower, char auxTower)
  {
    if (n==1) //stopping condition
    {
      System.out.println("Move disk "+n+" from "+fromTower+" to "+toTower);
      return 1;
    }
    else
    {
      int i1 = moveDisks(n-1, fromTower, auxTower, toTower);
      System.out.println("Move disk "+n+" from "+fromTower+" to "+toTower);
      i1++;
      return i1+moveDisks(n-1, auxTower, toTower, fromTower);
    }
  }

  /* what is wrong with this implementation?
     public static int moveDisks(int n, char fromTower, char toTower, char auxTower)
  {
    int numOfMoves = 0;

    if (n==1) //stopping condition
    {
      System.out.println("Move disk "+n+" from "+fromTower+" to "+toTower);
      numOfMoves++;
    }
    else
    {
      moveDisks(n-1, fromTower, auxTower, toTower);
      System.out.println("Move disk "+n+" from "+fromTower+" to "+toTower);
      numOfMoves++;
      moveDisks(n-1, auxTower, toTower, fromTower);
    }

    return numOfMoves;
  }*/
}
