Challenge: Solve Hanoi recursively
We'll cover the following
Solve the base case
In this challenge, you will solve the towers of Hanoi problem for five disks, by writing a recursive function solveHanoi()
that will solve Hanoi for any positive number of disks.
A call to solveHanoi(numDisks, fromPeg, toPeg)
should move numDisks
disks from the peg fromPeg
to the peg toPeg
.
Start by implementing the base case of zero disks.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy