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

Home > Algorithms
Three of Hanoi (Posted on 2005-07-01) Difficulty: 3 of 5
  • When solving the Towers of Hanoi puzzle, it's easy to show that on every other turn you must move the smallest disk... can you do this?
  • Then again, can you also prove that the smallest disk will move cyclically -- for example, from post 1 to post 2 to post 3 to post 1, and so on?
  • Finally, using that fact, can you provide an iterative (that is, not recursive) algorithm for solving the puzzle?
  •   Submitted by Federico Kereki    
    Rating: 4.5000 (2 votes)
    Solution: (Hide)
    To prove that every other move must be the small disc: after having moved it to a post, you have only one possible move that involves the other two posts -- and after doing that, your only chances will be either reversing the move you just did (not very wise...) or moving the smallest disc. QED.

    For the cyclical part: consider the recursive algorithm for moving N discs from post A to post B being C the other post: move N-1 discs from A to C, move the N-th disk from A to B, move N-1 discs from C to B. If N=1, the smallest disc will obviously move in a cycle (a very short one!). And for larger N, the algorithm will produce two equivalent cycles, with an added move (the N-th disk) inbetween.

    Finally, the algorithm. Let's suppose you want to move N discs from post 1 to post 3. The rule is: on every odd turn, move the smallest disc cyclically (if N is odd, make the cycle 1-3-2-1-3-2; if even, 1-2-3-1-2-3), and on every even turn do whatever you can that doesn't involve the smallest disc.

    Comments: ( You must be logged in to post comments.)
      Subject Author Date
    QuestionArjun2007-09-08 12:24:04
    My solutionJort Bloem2006-10-23 23:14:50
    SolutionOne good solution, one so-so solutione.g.2005-07-02 14:03:33
    Please log in:
    Login:
    Password:
    Remember me:
    Sign up! | Forgot password


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

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