## 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 pegs, and a number of disks of different sizes which can slide onto any peg. The puzzle starts with the disks in a neat stack in ascending order of size on one peg, the smallest at the top, thus forming a pyramid.

The objective of the puzzle is to move the entire stack to another peg, obeying the following rules:

- Only one disk may be moved at a time.
- Each move consists of taking the upper disk from one of the pegs and sliding it onto another peg, on top of the other disks that may already be present on that peg.
- No disk may be placed on top of a smaller disk.

### Traguardo dell'esercizio

Write the core of the method: `[!java|c]void [/!]hanoi[!c]Rec[/!]([!java|c]int [/!]height[!scala]:Int[/!], [!java|c]int [/!]src[!scala]:Int[/!], [!java|c]int [/!]other[!scala]:Int[/!],[!java|c]int [/!]dst[!scala]:Int[/!])`

This method will recursively solve the presented problem. The first parameter named `height` is the height of the tower to move; The second parameter `src` is the index of the initial tower, the third parameter `other` is the index of the unused peg while the fourth parameter `dst` is the index of the expected final 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.

Here is the pseudo-code of the solution:

- label the pegs A, B, C (these labels may move at different steps)
- let n be the total number of discs (the height of the initial tower)
- number the discs from 1 (smallest, topmost) to n (largest, bottommost)

To move n discs from peg A to peg C:

- move n−1 discs from A to B. This leaves disc number n alone on peg A
- move disc number n from A to C
- move n−1 discs from B to C so they sit on disc number n