Tower of hanoi with 4 pole

This is a discussion on Tower of hanoi with 4 pole within the C Programming forums, part of the General Programming Boards category; l need help to do this programm please help me...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    3

    Tower of hanoi with 4 pole

    l need help to do this programm
    please help me

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,166
    I have never heard of such a variant of the problem, but if you want help, refer to our homework policy.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    However many poles you have (and do double check the number), the basic process is the same, to play the puzzle:

    1) Call one pole the "answer" pole.
    2) Call the pole with the rings now, the "source" pole.
    3) Anything else is an auxillary pole ("aux").

    Then unload source rings to the aux poles, until no more rings can be handled. Then move the next ring (the largest you have access to at that time), to an empty aux pole. Now using the source pole as temporary storage, move all the rings from the other aux and answer pole, to the aux pole, in proper order by size. The answer pole will serve as temporary storage, for now. Later, the source pole will replace the answer pole as temporary storage once it is empty.

    So what you're doing is recreating the original stack of rings, but on the aux pole, not the source pole (and not the answer pole, either).

    Keep doing this until you have all but the largest ring from the source pole, stacked up on one of the aux poles. Now move the largest ring from the source pole to the answer pole. Last, use the now empty source pole as an aux pole, to shift all the other rings from their stack on the aux pole, to the answer pole, by repeating this step (make a new stack, then move the largest unordered ring from the aux or source pole, to the answer pole).

    If you play the game several times, you'll see the pattern. If you can't find a game with 4 poles, and that's what's needed, I recommend you make your own out of either paper rings you cut out with scissors, or some washers of different sizes. A few straws might serve as the poles, when stuck into a little holder (like maybe a plastic cup lid?).

    It's a beautiful example of a recursive program, but I would NOT call it trivial.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 02:34 PM
  2. Little Problem on Presentation in the Tower of Hanoi
    By momegao in forum C++ Programming
    Replies: 3
    Last Post: 04-20-2003, 07:22 PM
  3. Tower of Hanoi
    By carrja99 in forum C++ Programming
    Replies: 2
    Last Post: 02-09-2003, 12:15 PM
  4. Hanoi tower
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 07:35 PM
  5. Tower Of Hanoi
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 12-18-2001, 11:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21