Solve 4 Pegs Hanoi Tower: Algorithm & Best Move Ideas

  • Thread starter Thread starter Stephanus
  • Start date Start date
  • Tags Tags
    tower
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
5 replies · 3K views
Stephanus
Messages
1,316
Reaction score
104
Dear PF Forum,
Do anybody know the algorithm for 4 pegs Hanoi Tower?
In regular initial, we can use array.
But what if the initial configuration is random?
I can do it in 3 pegs, but I've been searching algorithm for 4 pegs every day, on my bed, before I go to sleep. But I can't find any.
The algorithm should find the best move. Not using "brute force"!

Thanks for any idea.

Steven
 
Physics news on Phys.org
The standard way is to use a recursive algorithm:
  1. 3 disks can be done directly.
  2. Assume that you have found how to do it with n disks
    • Use this to move n disks to one of the spare pegs
    • Move the bottom disk to the goal peg
    • Move the n disks from the spare peg to the goal peg.
 
  • Like
Likes   Reactions: Stephanus
Svein said:
The standard way is to use a recursive algorithm:
  1. 3 disks can be done directly.
  2. Assume that you have found how to do it with n disks
    • Use this to move n disks to one of the spare pegs
    • Move the bottom disk to the goal peg
    • Move the n disks from the spare peg to the goal peg.
Yes, of course Svein. But it's not the best/shortest move is it?
 
mfb said:
According to Wikipedia, the optimal solution with 4 pegs http://Tower_of_Hanoi#With_four_pegs_and_beyond . And randomizing the starting position certainly does not help.

Thanks mfb,
There is, actually, an algorithm for a sorted initial position, but for a random position, well... Maybe? I've been trying for two months before I sleep. Still can't find solutions. Perhaps you're right.
 
Last edited by a moderator:
(I fixed the link in the previous post)

On the positive side, if you find an efficient algorithm, you can write a paper about it.
 
  • Like
Likes   Reactions: Stephanus