All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Towers of Hanoi variation (Posted on 2005-05-03) Difficulty: 3 of 5
There are some poles, and on the first pole are some rings, each a different size. The sizes of the rings increases from the top to the bottom of the pole. The only allowable move is to take the top ring from any pole and place onto another pole. You cannot place a ring on top of another ring unless the other ring is exactly one size bigger. You can make as many moves as you like.

Your goal is to move all the rings onto the second pole, in the same order. What is the highest number of rings that can be moved when there are N poles? How can you move this many rings?

See The Solution Submitted by Tristan    
Rating: 4.0000 (4 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Movement algorithm - spoiler? | Comment 6 of 14 |
I got to thinking that my description in my earlier post was a bit vague concerning the movement algorithm.  For this post, rings will be labeled a, b, c, ... with 'a' being the smallest ring, and poles labeled 0, 1, 2, ... with '0' being the original, or starting pole.

Remember that for 'n' empty poles, you can move 1/2 * (n + n) rings.

1 pole (trivial):
Move ring a to pole 1.

2 poles (3 rings):
Move ring a to pole 1, move ring b to pole 2, move ring a to pole 2.
Move ring c to pole 1.
Move ring a to pole 0, move ring b to pole 1, move ring a to pole 1.

3 poles (6 rings):
Move ring a to pole 1, move ring b to pole 2, move ring c to pole 3, move ring b to pole 3, move ring a to pole 3.
Move ring d to pole 1, move ring e to pole 2, move ring d to pole 2.
Move ring f to pole 1.
Move ring d to pole 0, move ring e to pole 1, move ring d to pole 1.
Move ring a to pole 0, move ring b to pole 2, move ring c to pole 1, move ring b to pole 1, move ring a to pole 1.

As you can see, moving the three larger rings in the 6 ring solution is exactly the same as the 3 ring solution.  The basic strategy is that you pull rings off the stack and put them on an empty pole until there are no more empty poles, then you put the smaller rings on top of the largest ring you pulled off the original stack.  You repeat this process until you have only 1 empty pole available then you move the bottom-most ring from the stack to that pole.  At the time you move the bottom-most ring you will see that each next pole has one more ring than the previous pole, just like dot diagrams of triangular numbers.
  Posted by Erik O. on 2005-05-03 17:53:06
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (8)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2014 by Animus Pactum Consulting. All rights reserved. Privacy Information