Tower of Hanoi

The Tower of Hanoi or Towers of Hanoi , also called the Tower of Brahma or Towers of Brahma, is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus forming a pyramid. The objective of the puzzle is to move the entire stack to another rod, obeying the following rules:

Goal of this exercise

Write the core of the method: [!java]void [/!]solve([!java]int [/!]src[!scala]:Int[/!], [!java]int [/!]dst[!scala]:Int[/!], [!java]int [/!]height[!scala]:Int[/!]) This method will recursively solve the presented problem. First parameter named src is the index of the initial tower, second parameter dst is the index of the expected final tower, and the third parameter height is the height of the tower. A key to solving this puzzle is to recognize that it can be solved by breaking the problem down into a collection of smaller problems and further breaking those problems down into even smaller problems until a solution is reached. The following procedure demonstrates this approach: To move n discs from peg A to peg C: