Anonymous user
Towers of Hanoi: Difference between revisions
m
→simple text moves: added/changed comments and whitespace.
(→{{header|Pascal}}: adding PARI/GP version) |
m (→simple text moves: added/changed comments and whitespace.) |
||
Line 2,804:
=={{header|REXX}}==
===simple text moves===
<lang rexx>/*REXX program
parse arg N . /*get optional number of disks from CL.*/
if N=='' | N=="," then N=3 /*Not
#=0
call mov 1, 3, N /*move the top disk, then recurse ··· */
say
say 'The minimum number of moves to solve a ' N"-disk Tower of Hanoi is " z
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
dsk: #=#+1 /*bump the (disk) move counter by one. */
say 'step' right(#, length(z))": move disk on tower" arg(1) '───►' arg(2)
return /* [↑] display the move message (text)*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
mov: procedure expose # z; parse arg @1, @2, @3
if @3==1 then call dsk @1, @2
else do; call mov @1, 6-@1-@2, @3-1
call mov @1,
call mov 6-@1-@2,
end
return</lang>
|