Approached the towers of hanoi problem and was wondering why my output starts at "disk 1".
Based on how the code is written to be (taken from geeksforgeeks website), shouldn't the expected output be:
"Move disk 4 from rod A to rod C."
and then once it is called again (n-1) the output should be:
"Move disk 3 from rod B to rod C."
I don't understand how it logs starting from disk 1.
function towersOfHanoi(n,f,t,a) {
if (n==0){
return;
}
towersOfHanoi(n-1, f, a, t);
console.log("Move disk "+ n + " from rod " + f +" to rod "+ t +".")
towersOfHanoi(n-1, a, t, f);
}
let N = 4;
towersOfHanoi(N,"A","C","B");