Question: Task 1 ( 2 0 % ) Problem: Write a recursive program that prints the steps for solving reverse Tower of Hanoi. The rules

Task 1(20\%)
Problem: Write a recursive program that prints the steps for solving "reverse" Tower of Hanoi. The rules are explained using the figure below.
Key points
- As depicted in the above figure, the pegs are upside down and the disks are held at the top using magnets.
- The order of disks in a tower is the same: smallest disk at the top, largest disk at the bottom.
- The movement of disks is reversed: you can only move the largest disk from the bottom of one tower to the bottom of a smaller disk in another tower (or onto an empty peg).
- You will implement the reverseToH(...) method. Do not change the signature for this method. This method needs to be recursive.
Hint: You will find that this problem looks similar to the original Tower of Hanoi puzzle. Solution to the Tower of Hanoi puzzle is a recursive algorithm, and it is covered in Week 15(see recording for Week 15- Lecture 1).
The listing below shows the output that your program needs to print (Lines 6-12 below) for the sample input given in Run.java (Lines 1-4 below). The first three steps are depicted in the above figure.
```
Task1 t1= new Task1();
int size =3;
t1.setTowerSize(size);
t1.reverseToH(size ,1,3);
Move Disk 3 from Peg 1 to Peg 3
Move Disk 2 from Peg 1 to Peg 2
Move Disk 3 from Peg 3 to Peg 2
Move Disk 1 from Peg 1 to Peg 3
Move Disk 3 from Peg 2 to Peg 1
Move Disk 2 from Peg 2 to Peg 3
Move Disk 3 from Peg 1 to Peg 3
```
Task 1 ( 2 0 \ % ) Problem: Write a recursive

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!