Recursive approach to solving the Towers of Hanoi puzzle
<p>I'm trying to work out the "towers of hanoi" problem, which moves stacks of disks organized from smallest to largest from a start stack to a destination stack, by means of an auxiliary stack without ever placing a larger disk on top of a smaller disk.</p>

<p>I was given the algorithim:</p>

<pre><code>If numberDisks ==  1:
   Display “Move the top disk from  S to D”.
Else
  Move(numberDisks -1, ‘S’, ‘A’, ‘D’);
  Move(1, ‘S’, ‘D’, ‘A’);
  Move(numberDisks -1, ‘A’, ‘D’, ‘S’);
</code></pre>

<p>However this seems to differ from most other <a href="https://youtu.be/CvVOpAfTFUM?t=3m38s" rel="nofollow">examples</a> which seem to work without using Move(1, ‘S’, ‘D’, ‘A’); in the recursive function.</p>

<p>As my code stands, I seem repeat the base case for every move, and im not sure how to structure my print statements to give the proper output which should look like:</p>

<pre><code>Move disk 1 from S to D
Move disk 2 from S to A
Move disk 1 from D to A
Move disk 3 from S to D
Move disk 1 from A to S
Move disk 2 from A to D
Move disk 1 from S to D
</code></pre>

<p>When trying to move 3 disks.</p>

<pre><code>// Recursively solve Towers of Hanoi puzzle

public static void main(String[] args) {
    if (handleArguments(args)) {
        System.out.println("numDisks is ok");
        int numDisks = Integer.parseInt(args[0]);

        Move(numDisks,'s', 'a', 'd' );
    }
}

// recursive case
public static void Move(int disks, char start, char aux, char destination) {

    // base case
    if (disks == 1) {
        System.out.println("Move disk 1 from S to D");

        // if number of disks is 2 or greater
    } else if(disks &gt; 1) {
        Move(disks - 1, start, aux, destination);
        System.out.println("move disk " + disks + " from " + start + " to " + destination);
        Move(1, start, destination, aux);
        Move(disks - 1, aux, destination, start);
    }
}
</code></pre>