Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@RUPOJS
Last active August 29, 2015 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RUPOJS/f0f72758324e7b99c1e1 to your computer and use it in GitHub Desktop.
Save RUPOJS/f0f72758324e7b99c1e1 to your computer and use it in GitHub Desktop.
Tower of Hanoi implementation in JavaScript using recursion
var write = function(string) {
document.write(string);
}
var i = 0;
var hanoi = function(disc,src,aux,dst) {
if (disc > 0) {
hanoi(disc - 1,src,dst,aux);
write("Move disc " + disc + " from " + src + " to " + dst + "<br />");
hanoi(disc - 1,aux,src,dst);
}
};
hanoi(3,"src","aux","dst");
// for more, please see - http://www.geeksforgeeks.org/iterative-tower-of-hanoi/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment