# Hanoi with Four Pegs ## Metadata **Status**:: #x **Zettel**:: #zettel/fleeting **Created**:: [[2026-01-27]] ## Synopsis Assume there are 4 pegs named a, b, c, and d. The objective is moving n disks from a to b. - Move n-k disks from a to d using b and c as temporary pegs. - Move k disks from a to b using c as a temporary peg. - Move n-k disks from d to b using a and c as temporary pegs. The optimal k is $\left\lfloor \sqrt{2n+1} \right\rceil - 1$ where $\left\lfloor \cdot \right\rceil$ is the nearest integer function. This can be generalized into multi-pegs (Frame–Stewart algorithm) - Move n-k disks with p pegs - Move k disks with p-1 pegs - Move n-k disks with p pegs The optimal k is not known for p > 4. ## References - Demontis, R. (2012, March 15). What is the least number of moves needed to solve the k-peg Towers of Hanoi problem? arXiv.Org. https://arxiv.org/abs/1203.3280