I am befuddled by the recursive solution for Towers of Hanoi that decrements a disc argument on each recursive call without starting at the initiated value of disc nor ending the recursion after disc amount of calls.
Shouldn't disc - 1 reach the value 0 after disc amount of calls? Where is the magician's hand in this elegant trick? Why does each new call seem to be working on its own disc value rather than the original argument?
function hanoi(disc, src, dst, aux) {
if (disc === 0) {
var disk = src.pop();
dst.push(disk);
} else {
hanoi(disc-1, src, aux, dst);
var disk = src.pop();
dst.push(disk);
hanoi(disc-1, aux, dst, src);
}
}
hanoi(10, [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [], []);