aUCBLogo Demos and Tests / hanoi
; This program solves the 5-disk tower of hanoi problem.
to hanoi [number 5][from "a][onto "b][other "c]
; Recursive procedure that solves a subproblem of the original problem,
; moving some number of disks, not necessarily 5. To move n disks, it
; must get the topmost n-1 out of the way, move the nth to the target
; stack, then move the n-1 to the target stack.
if number != 0
[ (hanoi number-1 from other onto)
movedisk number from onto
(hanoi number-1 other onto from)
]
end
to movedisk number from onto
; This procedure moves one single disk. It assumes that the move is
; legal, i.e., the disk is at the top of its stack and the target stack
; has no smaller disks already. Procedure hanoi is responsible for
; making sure that's all true.}
(pr [Move disk ] number [ from ] from [ to ] onto)
end