Towers of Hanoi: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: removed some superflous blank lines. -- ~~~~) |
|||
Line 1,621: | Line 1,621: | ||
===version 1=== |
===version 1=== |
||
<lang rexx>/*REXX program to show the moves to solve the Tower of Hanoi (3 disks). */ |
<lang rexx>/*REXX program to show the moves to solve the Tower of Hanoi (3 disks). */ |
||
arg z . |
arg z . |
||
if z=='' then z=3 |
if z=='' then z=3 |
||
Line 1,630: | Line 1,629: | ||
say 'The minimum number of moves to solve a' z "ring Tower of Hanoi is" moves'.' |
say 'The minimum number of moves to solve a' z "ring Tower of Hanoi is" moves'.' |
||
exit |
exit |
||
/*─────────────────────────────MOV subroutine───────────────────────────*/ |
/*─────────────────────────────MOV subroutine───────────────────────────*/ |
||
mov: if arg(3)==1 then call dsk arg(1),arg(2) |
mov: if arg(3)==1 then call dsk arg(1),arg(2) |
||
Line 1,640: | Line 1,637: | ||
end |
end |
||
return |
return |
||
/*─────────────────────────────DSK subroutine───────────────────────────*/ |
/*─────────────────────────────DSK subroutine───────────────────────────*/ |
||
dsk: move=move+1 |
dsk: move=move+1 |
||
Line 1,688: | Line 1,683: | ||
No attempt is mode to explain this REXX code because of the complexity and somewhat obtuse features of the REXX language, the smallest of which is support for ASCII and EBCDIC "graphic" characters. |
No attempt is mode to explain this REXX code because of the complexity and somewhat obtuse features of the REXX language, the smallest of which is support for ASCII and EBCDIC "graphic" characters. |
||
<lang rexx>/*REXX program shows pictorial moves to solve Tower of Hanoi (3 disks). */ |
<lang rexx>/*REXX program shows pictorial moves to solve Tower of Hanoi (3 disks). */ |
||
⚫ | |||
arg z . |
|||
⚫ | |||
sw=80 |
sw=80 |
||
wp=sw%3-1 |
wp=sw%3-1 |
||
Line 1,738: | Line 1,731: | ||
say "The minimum number of moves for a" z 'ring Tower of Hanoi is' totmoves |
say "The minimum number of moves for a" z 'ring Tower of Hanoi is' totmoves |
||
exit |
exit |
||
/*─────────────────────────────MOV subroutine───────────────────────────*/ |
/*─────────────────────────────MOV subroutine───────────────────────────*/ |
||
mov: if arg(3)==1 then call rng arg(1) arg(2) |
mov: if arg(3)==1 then call rng arg(1) arg(2) |
||
Line 1,748: | Line 1,739: | ||
end |
end |
||
return |
return |
||
/*─────────────────────────────RNG subroutine───────────────────────────*/ |
/*─────────────────────────────RNG subroutine───────────────────────────*/ |
||
rng: parse arg from dest |
rng: parse arg from dest |
||
Line 1,797: | Line 1,786: | ||
call showtowers |
call showtowers |
||
return |
return |
||
/*─────────────────────────────SHOWTOWERS subroutine────────────────────*/ |
/*─────────────────────────────SHOWTOWERS subroutine────────────────────*/ |
||
showtowers: do j=z to 1 by -1 |
showtowers: do j=z to 1 by -1 |