Thread: Tower of hanoi with 4 pole

  1. #1
    Registered User
    Join Date
    Jan 2008

    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
    I have never heard of such a variant of the problem, but if you want help, refer to our homework policy.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2006
    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, 01: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, 06: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, 06:35 PM
  5. Tower Of Hanoi
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 12-18-2001, 11:12 PM