0
votes

I am trying to solve a Variation of the Towers of Hanoi. In this case I have two towers, same height and the disks have the same sizes. I can stack disks onto each other as long as they are the same size or smaller. The color does not factor in to the stacking capabilities.

I have three pegs and two towers and the task is to swap both towers.

My initial approach is to build one tower with alternating colors and then going backwards with just a different peg to move to.

I am just thinking that this is not the most elegant solution. Is there a better way to do this?

Update:
I thought I was pretty close to figuring this out, but I wasn't. I have all the moves (for n=3) on paper and it looks pretty similar to the original algorithm just that lots of moves are done twice. Unfortunately I am not able to put this into a recursive algorithm. This is pretty frustrating. Does someone have an idea?

1
"three pegs and two towers" - as in "initally two of the tree pegs contain 1-1 tower"?Karoly Horvath
Yes two of the three pegs contain a tower each. Same height, same disk sizes just different colors (say one green, one red). Both need to get swapped in their position.sebastian

1 Answers

0
votes

There is a website that addresses various versions of the Tower of Hanoi.

Also, if you want to do this recursively, you don't actually need to know what is going to happen. You can just try all available moves recursively until you reach the solution.