From 52b5eb618b14f77381a62135be26ac6f41f60437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Fernando=20Ushi=C3=B1a?= Date: Sat, 23 Jan 2021 18:32:11 -0500 Subject: [PATCH] sample tower of hanoi in nodejs --- 23-01-2021/hanoi-tower.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 23-01-2021/hanoi-tower.js 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");