Last active
December 11, 2015 05:19
-
-
Save cacciatc/4551723 to your computer and use it in GitHub Desktop.
Towers Of Hanoi
This file contains 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
var hanoi = function(n, source, by, dest){ | |
if(n == 0) return; | |
// Move all the disks but the bottom disk (n – 1 disks) from the left pole to the middle pole. | |
hanoi(n-1,source,dest,by); | |
// Move the bottom disk to the right-most pole. | |
print("Move " + n + " from " + source + " to " + dest); | |
// Move all the disks from the middle pole (n – 1 disks) to the right-most pole. | |
hanoi(n-1,by,source,dest); | |
} | |
hanoi(3, 'A', 'B', 'C'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment