zuloocold.blogg.se

Four hanoi towers solution
Four hanoi towers solution













And now guess what - exactly! It is you who is sitting next to Charlie, and he is already glaring at you. Actually, the only thing Charlie is really good at is "sitting next to someone who can do the job". So the real problem is that problem solving does not belong to the things Charlie is good at. Well, I don't know an optimal algorithm for four towers. Calculate the smallest number of disk moves to move all the disks from tower A to tower D using all four towers."Ĭharlie looks irritated: "Urgh. The teacher sighs: "Well, Charlie, let's think about something for you to do: For you there is a fourth tower D.

FOUR HANOI TOWERS SOLUTION CODE

So your task is to write a program that calculates the smallest number of disk moves necessary to move all the disks from tower A to C."Ĭharlie: "This is incredibly boring-everybody knows that this can be solved using a simple recursion.I deny to code something as simple as this!" One disk at a time can be moved from the top of a tower either to an empty tower or to a tower with a larger disk on the top.The goal of the puzzle is to transfer all of the disks from tower A to tower C.

four hanoi towers solution

The disks are initially stacked on tower A increasing in size from the top to the bottom.The number n is constant while working the puzzle. The teacher points to the blackboard (Fig. Charlie Darkbrown sits in another one of those boring Computer Science lessons: At the moment the teacher just explains the standard Tower of Hanoi problem, which bores Charlie to death!













Four hanoi towers solution