Question
Write java code for the following towers of hanoi problem. There are 3 different pegs and 4 discs with given initial configuration and you have
Write java code for the following towers of hanoi problem.
There are 3 different pegs and 4 discs with given initial configuration and you have to get final configuration as mentioned below. The discs are in ascending order.
1 .Initial Configuration: ABCA
Final Configuration: ACBC
The problem is to transform ABCA ACBC, Because the big disk is on the same tower in both configurations, we can just ignore the big disk and the solution to the 4 disk problem immediately reduces to the 3 disk problem: transform BCA CBC
2. Initial Configuration: ABCA
Final Configuration: BCAA
The problem is to transform ABCA BCAA Because the big disk is not on the same tower, we will have to move it from A to B. Before we can do this, we have to clear off any disks on top of the big disk, and get tower B empty. (Hint for 2 : Stage 1:From the Initial Configuration, get all but the big disk on tower C: ABCA ACCC Stage 2: Move the big disk from A to B: ACCC BCCC Stage 3: Get the disks off tower C and onto the towers where they belong in the final configuration: BCCC BCAA)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started