hanoi tower

do you know how to play the Hanoi Tower game?
Please desire a Hanoi Tower game.
you can go to this wed site to see what is the Hanoi Tower game.

http://www.math.toronto.edu/mathnet/games/towers.html
ahyangAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ahyangAuthor Commented:
if possiple, please finish at 23/11/99.
Thanks!
0
StefanZCommented:
THe idea of hanoi tower is to move the all rings from one pipe to the other using a help pipe.
You are allowd to move everything to everywhere EXCEPT to put larger ring over smaller
Thanks
0
vikiingCommented:
That's one of the most ellegant recursive solutions of a problem like this (a half dozen instructions do the job).

The most incredibly: Hanoi's Towers is not a legend, but a reality, because those ancient monks are REALLY moving plates back and forth since several centuries ago.

The total amount of movements is (2^n)-1 , where n equals the number of plates. Thus, the result is, for 64 disks, is 2 x 10^19 approx.. If you consider that each movement is done in 2 seconds, the total time is about 40 times THE AGE OF THE UNIVERSE (estimated in 15,000 millions of years).

Here you have a simple program that gives youu all the moves you have to do to solve a simple tower of 3 disks (let CP% be the quantity of disks you want):


        CP% = 5
        CALL HANOI(CP%, 1, 3, 2)

        SUB HANOI(Disks%, Orig%, Dest%, Aux%)
        IF Disks%<2       THEN
                ?"Move disk from";Orig%;"to";Dest%
                      ELSE
                CALL HANOI(Disks%-1, Orig%, Aux%, Dest%)
                CALL HANOI(     1       , Orig%  , Dest% ,    0    )
                CALL HANOI(Disks%-1, Aux%, Dest% , Orig% )
        END IF
        END SUB
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

vikiingCommented:
Opps !!!; to be 3 disks, let CP% equal 3, not 5. Sorry...
0
ozoCommented:
It was a marketing legend.
0
vikiingCommented:
>>It was a marketing legend

Sorry to say *I SAW* with my own eyes the monks working...
0
ahyangAuthor Commented:
Sorry, maybe my question no clear.  Now i write down again.
please use the c++ language  to desire the tower of hanoi game.
 you can go to this wed site to see what is the Hanoi Tower game.

http://www.math.toronto.edu/mathnet/games/towers.html

Thank's!
0
ozoCommented:
Where did you see the monks working? Did you see them working before 1883?  How many disks had they moved?
0
_lychee_Commented:
just for interests sake, here's an iterative algo... (haven't figgered how to make sure it ends on the correct pole though...)
basically,

label the discs from 1 to n
the rule is

1. never undo a move u just did
2. never put odd on odd or even on even

there'll only be 1 eligible move after the 1st move is made

:)
0
vikiingCommented:
For Ozo:

>>Where did you see the monks working?

Close to Tibet.


>>Did you see them working before 1883?

In 1974. The last reference I have was a Ripley's, in early 80's.


>>How many disks had they moved

I don't know. But the height of the stack of disks appeared to be not so big, perhaps 30 or 40, and I don't remember the exact quantity. Maybe an indian tour guide know the exact value. But I remember their prophecy: when the job be finished, that will be the End of the World (very common words among religious jobs... :)


For Lychee:

>>there'll only be 1 eligible move after the 1st move is made

The question is how to choose the first move wisely, because if it's bad the game can't be solved. But it can be deducted this way: assuming the sequence of poles is 1-2-3, and all disk are piled at the beginning at pole 1, the first move must be done so: if "n" (the amount of disks) is odd, then the first move must be done to the odd numbered pole (3); if it's even, to the even one (2).

Therefore, if you have 2/4/6/8... disks, the first move is always "1 to 2"; on the other hand, if you have 3/5/7/9... disks, the first move is always "1 to 3". Starting from that, it's almost incredible how you can get automated in such a way (if you're a bit clever) that you can solve a relatively large game (let's say, 7 or 8 plates) with no error.
0
_lychee_Commented:
i think that sounds correct....
anyway, i think 1 more rule is needed...
u should move a disc on another if u can... (ie. try not to move onto a 'blank')

but even if the first move is wrong, after this rule is added the correct answer will be gotten too (just that it takes 2ce the shortest no of moves)
0
vikiingCommented:
BTW, ¿what does Ahyang say after all this stuff? ¿Is a C++ program what he needs?

I almost forgot C syntax, but it must be easy:

void Hanoi(int cp, orig, dest, aux)
{
        If (cp < 2) {
               printf("%u to %u", orig, dest);
        } else {
               Hanoi(cp-1, orig, aux , dest);
               Hanoi( 1  , orig, dest,   0 );
               Hanoi(cp-1, aux , dest, orig);
        }
}


main ()
{
        int cp;
        cp:=6;
        Hanoi(cp, 1, 3, 2);
}
0
vikiingCommented:
What a curiosity... I see you've accepted my answer, but I don't see it here.

¿Another EE bug?

Anyway, thanks for the points !!!
0
vikiingCommented:
What a curiosity... you've accepted my answer, but I can't find it here. ¿Another EE bug?... :(

Anyway, thanks for the points !!  :)

0
ComTechCommented:
Time to close this abandoned question.

ComTech
CS @ EE
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Hardware

From novice to tech pro — start learning today.