I like the algorithm mentioned in this question: "How does this work? Weird Towers of Hanoi Solution" How does this work? Weird Towers of Hanoi Solution
Is there any way to scale that non-recursive solution of Towers of Hanoi to use X disks and Y towers, with towers represented as stacks?
An iterative solution for the tower of Hanoi with Y=3 Towers and X discs and can be found on Wikipedia:
For an even number of disks:
For an odd number of disks:
In each case, a total of 2^X-1 moves are made. The number of moves with this algorithm is only minimal for Y=3.
This solution ignores the other towers, so it works with any Y >= 3 and any X.
Although the three-peg version has a simple recursive solution as outlined above, the optimal solution for the Tower of Hanoi problem with four pegs (called Reve's puzzle), let alone more pegs, is still an open problem. This is a good example of how a simple, solvable problem can be made dramatically more difficult by slightly loosening one of the problem constraints.
Quoted from Wikipedia.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With