Created
September 26, 2020 06:49
-
-
Save housecricket/fa7388bc53351bbb2da4cb0bde3abafc to your computer and use it in GitHub Desktop.
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
/* | |
* s, d, e represents three pegs (source, destination and extra). | |
* n is number of discs (All initially in s) | |
*/ | |
resolver_tower_of_hanoi = function (s, d, e, n) { | |
// terminating condition | |
if (n <= 0) { | |
return | |
} | |
resolver_tower_of_hanoi(s, e, d, n - 1) | |
console.log(`Move Disk-${n} FROM ${s} TO ${d}`); | |
resolver_tower_of_hanoi(e, d, s, n - 1); | |
} | |
resolver_tower_of_hanoi('s', 'd', 'e', 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment