Anonymous user
Best shuffle: Difference between revisions
→{{header|REXX}}: elided a function, changed the bestShuffle function, added/changed whitespace and comments.
No edit summary |
(→{{header|REXX}}: elided a function, changed the bestShuffle function, added/changed whitespace and comments.) |
||
Line 2,660:
=={{header|REXX}}==
<lang rexx>/*REXX program
parse arg
if
w=0; #=words($) /* [↑]
do i=1 for
end /*i*/ /* [↑] ··· finds the widest word in @.*/▼
w=w+9 /*add 9 blanks for output indentation. */
do n=1 for
say 'original:' left(@.n, w) 'new:' left(new,w) 'count:' same
end /*n*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
bestShuffle: procedure;
do j=1 for L-1; parse var x =(j) a +1 b +1 /*get A,B at Jth & J+1 pos.*/
x=overlay(
x=overlay(y, overlay(a,x, lastpos(y,x)),j+1) /*fast swap of 2 characters*/
do
a= substr( x,
b= substr(
▲ x=overlay(a,x,_); x=overlay(y,x,jp) /*fast way to swap chars. */
▲ end /*j*/
▲ do k=1 for Lx /*handle a possible rep. */
▲ b= substr(ox, k, 1) /*obtain the original char*/
▲ if a\==b then iterate /*skip non-replications. */
end /*k*/
return x</lang>
'''output''' (with a freebie thrown in):
<pre>
|