Created
March 2, 2014 17:06
-
-
Save richistron/9309723 to your computer and use it in GitHub Desktop.
Hanoi towers recursive function with JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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