Skip to content

Instantly share code, notes, and snippets.

@shannah
Created December 7, 2012 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shannah/4229920 to your computer and use it in GitHub Desktop.
Save shannah/4229920 to your computer and use it in GitHub Desktop.
Towers of Hanoi changed to use object methods instead of static methods.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.myapp;
/**
*
* @author shannah
*/
public class TowersOfHanoi {
public int counter = 0;
public void move(int n, int startPole, int endPole) {
if (n == 0) {
return;
}
int intermediatePole = 6 - startPole - endPole;
move(n - 1, startPole, intermediatePole);
//System.out.println("Move " + n + " from " + startPole + " to " + endPole);
move(n - 1, intermediatePole, endPole);
counter++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment