Skip to content

Towers of Hanoi

editable example

Click the pencil to open this in an editor, change it, and run it in your browser. The same solution is posted on Rosetta Code.

ghul
use IO.Std.write_line
move(disks: int, source: int, target: int, spare: int) -> void =>
if disks > 0 then
move(disks - 1, source, spare, target)
write_line("move a disk from pole {source} to pole {target}")
move(disks - 1, spare, target, source)
fi
move(3, 1, 3, 2)