The puzzle can be solved by a recursive algorithm. To move a stack of n discs from the source peg to the destination peg, do the following steps in order:
1. Move the top n-1 discs to the spare peg.
2. Move disc n to the destination peg.
3. Move the stack of n-1 discs on top of disc n.
This algorithm works because this reduces the puzzle of n discs to a puzzle of only n-1 discs. That in turn is reduced to a puzzle of n-2 discs, and so on until the puzzle is reduced to moving a stack containing only 1 disc, which is trivial.
For example, the solution for small number of discs are as follows: