2

Suppose we have three rods A, B and C, and rod A contains n disks (Exactly like the original Tower of Hanoi problem). The disks are numbered 1 to n, when the bottom disk is number 1 and the top disk is number n.

I want to build two towers: One on rod B which contains only the odd numbered disks and one on rod C which contains only the even numbered disks. The laws of disk moving is exactly like in the original problem.

I am trying to think if it is possible to solve it with only three rods, and if it is how can it be solved recursively.

I thought about moving the top two disks by hand (maybe depends on the parity of n) and then perform a recursive call, but I am not sure at all how to do it.

Daniel
  • 129
  • 4

1 Answers1

2

Let $T_i$ be the tower defined by disks: $i,\dotsc,n$.

Here is a simple recursive algorithm:

Initialize i := 1
while(i != n+1)
    If i is even: 
           move the tower T(i+1) on any rod other than C using the standard Tower of Hanoi algorithm. 
           move disk i to rod C
    else:
           move the tower T(i+1) on any rod other than B using the standard Tower of Hanoi algorithm. 
           move disk i to rod B
    i <- i+1
end
Inuyasha Yagami
  • 6,277
  • 1
  • 12
  • 23