Towers of Hanoi: Difference between revisions

Added AppleScript version
No edit summary
(Added AppleScript version)
Line 2:
 
In this task, the goal is to solve the Towers of Hanoi problem with recursivity.
 
==[[AppleScript]]==
[[Category:AppleScript]]
global moves --this is so the handler 'hanoi' can see the 'moves' variable
set moves to ""
hanoi(4, "peg A", "peg C", "peg B")
on hanoi(ndisks, fromPeg, toPeg, withPeg)
if ndisks is greater than 0 then
hanoi(ndisks - 1, fromPeg, withPeg, toPeg)
set moves to moves & "Move disk " & ndisks & " from " & fromPeg & " to " & toPeg & return
hanoi(ndisks - 1, withPeg, toPeg, fromPeg)
end if
return moves
end hanoi
 
==[[Python]]==
Anonymous user