Last active
October 14, 2017 01:54
-
-
Save Nick0603/d2a1f0044b73423e44c0b9c22a04848e 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
function hanoi(n,A,B,C){ | |
if(n == 1){ | |
console.log("從塔" + A + "移動至" + C) | |
}else{ | |
hanoi(n-1,A,C,B); | |
hanoi(1,A,B,C); | |
hanoi(n-1,B,A,C); | |
} | |
} | |
var n = prompt("幾層的河內塔"); | |
hanoi(n,"A","B","C"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment