Skip to content

Instantly share code, notes, and snippets.

@richistron
Created March 2, 2014 17:06
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 richistron/9309723 to your computer and use it in GitHub Desktop.
Save richistron/9309723 to your computer and use it in GitHub Desktop.
Hanoi towers recursive function with JavaScript
/*
* Hanoi recursive function
*/
var hanoi = function(disc,src,aux,dest){
if(disc > 0){
hanoi(disc -1,src,dest,aux);
console.log('Move disc '+disc+' from '+src+' to '+dest);
hanoi(disc -1,aux,src,dest);
}
};
hanoi(3,'src','aux','dest');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment