Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var n=1,a,b,c,i=1;
$().ready(function(){
    console.clear();
    n=prompt("輸入層數",1);
    hanoi(n,"左","中","右");
});
function hanoi(n,a,b,c){
    if(n==1) {
        console.log(i+++":將-"+n+"-從  "+a+" ,移到  "+c);
        return;
    }
    hanoi(n-1,a,c,b);
    console.log(i+++":將-"+n+"-從  "+a+" ,移到  "+c);
    hanoi(n-1,b,a,c);
}
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
yaoyao34pro
0viewers