Tower of Hanoi/Variant

Problem
There is a tower of $n$ disks, stacked in decreasing size on one of $3$ pegs.


 * Tower of Hanoi.jpeg

The object of the exercise is to move the disks onto a different peg, obeying the rules:
 * $(1): \quad$ Only one disk can be moved at a time
 * $(2): \quad$ No disk may be placed on a peg with a smaller disk beneath it
 * $(3): \quad$ The disks must all be moved from the peg $1$ to peg $3$
 * $(4): \quad$ A move consists of transferring a disk from the peg $1$ to peg $2$, or back, or from peg $2$ to peg $3$, or back
 * $(5): \quad$ No disk can cross over peg $2$ if it contains a smaller disk.

Solution
For a tower of $n$ disks, it takes $3^n - 1$ moves.

Proof
To move a tower of $n$ disks from the peg $1$ to peg $3$, the following must happen:


 * $(1): \quad$ The tower of $n - 1$ disks above the $n$th disk is transferred from peg $1$ to peg $3$.
 * $(2): \quad$ The $n$th disk is transferred from peg $1$ to peg $2$.
 * $(3): \quad$ The tower of $n - 1$ disks above the $n$th disk is transferred from the peg $3$ to peg $1$.
 * $(4): \quad$ The $n$th disk is transferred from the peg $2$ to peg $3$.
 * $(5): \quad$ The tower of $n - 1$ disks above the $n$th disk is transferred from the peg $1$ to peg $3$.

Let ${T_n}'$ be the number of moves needed to transfer the $n$-disk tower from peg $1$ to peg $3$.

Then we see that:
 * ${T_n}' = 3 {T_{n - 1}}' + 2$

A simple proof by induction shows that:
 * ${T_n}' = 3^n - 1$