Question: Given n (=3) discs: disc1, disc2, diskc3 stacked on the leftmost peg in order of size with the largest disc at the bottom and a

Given n (=3) discs: disc1, disc2, diskc3 stacked on the leftmost peg in order of size with the largest disc at the bottom and a disc is always smaller than the disc below.

Move all three (n) discs from leftmost Peg A to rightmost Peg C with the following rules:

Only one disc may be moved at a time.

A disc can not be placed on the top of a smaller disc.

There are only three pegs: A, B, C

Write the program to display every move and indicate the position of each disc:

Beginning position of three discs: (A, A, A) (Position of disc 1, Position of disc 2, position of disc 3)

Disc 1 is smaller than disc 2 and disc 2 is smaller than disc 3.

Move disc 1 from Peg A to Peg C (C, A, A)

Move disc 2 from Peg A to Peg B (C, B, A)

Move disc 1 from Peg C to Peg B (B, B, A)

Etc. ..

Last move

Move disc 1 from Peg A to Peg C (C, C, C)

Do the same for n=4 discs.

Do the same for n= 5 discs.

Your program output must show proper information to be understood well

by the reader/viewer.

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 Databases Questions!