> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/t/towers_of_hanoi.md).

# Towers of Hanoi

```ruby
func hanoi(n, from=1, to=2, via=3) {
    if (n == 1) {
        say "Move disk from pole #{from} to pole #{to}."
    } else {
        hanoi(n-1, from, via,   to)
        hanoi(  1, from,  to,  via)
        hanoi(n-1,  via,  to, from)
    }
}
 
hanoi(4)
```
