📄 tower_of_hanoi.js
/home/palash/git/misc/algorithms/ex/tower_of_hanoi.js
Language: js • Lines: 22
var moveCounter = 0;
function move(n, source, auxiliary, dest) {
    if(n === 0){
        return
    }
    if(n === 1){
        console.log("Moving", n, "from", source, "to", dest)
        moveCounter++
        return
    }
    move(n-1, source, dest, auxiliary);
    console.log("Moving", n, "from", source, "to", dest)
    moveCounter++
    move(n-1, auxiliary, source, dest)

}

for(var i = 0; i <= 10101010101010101010; i++){
    moveCounter = 0;
    move(i, 'S', 'A', 'D')
    console.log("Number of disks", i, "Total move", moveCounter)
}