diff --git a/23-01-2021/hanoi-tower.js b/23-01-2021/hanoi-tower.js new file mode 100644 index 0000000..c1fcd74 --- /dev/null +++ b/23-01-2021/hanoi-tower.js @@ -0,0 +1,14 @@ +const hanoiTower = (numberDisk, source, destination, temp) => { + if (numberDisk == 1) { + console.log(`move from ${source} to ${destination}`); + return; + } + + hanoiTower(numberDisk - 1, source, temp, destination); + + console.log(`move disk ${numberDisk} from ${source} to ${destination}`); + + hanoiTower(numberDisk - 1, temp, destination, source); +}; + +hanoiTower(4, "A", "C", "B");