> I hope there is no specified order of distribution of the disks in the
> three towers except that they ARE indeed, ordered (a smaller disk
> restts on a bigger disk)
>
> Let us keep track of the sorted pile, initially sorted_pile = <disk1>
> and it'll be be on top of one of the towers.
>
> Every time, you need to move the entire "sorted pile" such that after
> move, the biggest / lowermost disk in the pile gets to sit on its
> successor. The successor is surely going to be either on the top of
> one of the other two disks, or below the sorted pile itslef (in which
> case no need to move, just sorted_pile++)
>
> But I don't think this is the best solution.
Here is the psedudocode:
void simple_Tower_of_honoi( from tower, to tower , auxilary tower, n)
{
move (n-1) disks from "from tower" to "auxilary tower" using "to
tower"
move the largest disk n from "from tower" to "to tower"
move (n-1) disks from "auxilary tower" to "to tower" using "from
tower"
}
void complex_tower_of_honoi()
{
do{
sorted_pile = <disk 1> (smallest disk).
biggest_disk_in_pile = 1;
tower_of_sorted_pile = towerof(disk 1)
next_disk = biggest_disk_in_pile + 1;
switch (towerof(next disk))
{
case tower_of_sorted_pile:
/* Disk is directly below sorted pile */
sorted_pile_add (next_disk)
biggest_disk_in_pile += 1
next_disk = biggest_disk_in_pile + 1;
break;
case other tower1:
simple_tower_of_honoi( tower_of_sorted_pile,
towerof(next_disk), remaining tower, biggest_disk_in_pile)
sorted_pile_add (next_disk)
biggest_disk_in_pile += 1
next_disk = biggest_disk_in_pile + 1;
break;
case other tower2:
simple_tower_of_honoi( tower_of_sorted_pile,
towerof(next_disk), remaining tower, biggest_disk_in_pile)
sorted_pile_add (next_disk)
biggest_disk_in_pile += 1
next_disk = biggest_disk_in_pile + 1;
break;
}
} while (biggest_disk_in_pile !=n)
Phew!
Does that look correct? I'm not sure.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---