Anonymous user
Towers of Hanoi: Difference between revisions
m
→simple text moves: added/changed comments and whitespace, simplified the program, used a template for the output section.
m (→Python recursive: (separating composition of the solution from its display)) |
m (→simple text moves: added/changed comments and whitespace, simplified the program, used a template for the output section.) |
||
Line 3,574:
parse arg N . /*get optional number of disks from CL.*/
if N=='' | N=="," then N=3 /*Not specified? Then use the default.*/
#=
z= 2**N -
call mov 1, 3, N /*move the top disk, then recurse ··· */
say 'The minimum number of moves to solve a ' N"
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
mov: procedure expose # z; parse arg @1,@2,@3; L= length(z)
▲dsk: #=#+1 /*bump the (disk) move counter by one. */
if
return
▲ end
▲'''output''' when using the default input:
<pre>
step 1: move disk on tower 1 ───► 3
|