Skip to content

Instantly share code, notes, and snippets.

@Nick0603
Last active October 14, 2017 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nick0603/d2a1f0044b73423e44c0b9c22a04848e to your computer and use it in GitHub Desktop.
Save Nick0603/d2a1f0044b73423e44c0b9c22a04848e to your computer and use it in GitHub Desktop.
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