Anonymous user
Permutations by swapping: Difference between revisions
m
→{{header|REXX}}: add/changed statejents, comments, whitespace, used a template for the output section.
(Scala contribution added.) |
m (→{{header|REXX}}: add/changed statejents, comments, whitespace, used a template for the output section.) |
||
Line 2,522:
=={{header|REXX}}==
<lang rexx>/*REXX program generates all permutations of N different objects by swapping.
parse arg things bunch . /*
if bunch
call permSets things, bunch /*invoke permutations by swapping sub. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
!: procedure; !=1;
/*──────────────────────────────────────────────────────────────────────────────────────*/
permSets: procedure; parse arg x,y /*take X things Y at a time. */
!.=0; pad=left('', x*y)
z=left('123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', x); q=z
end /*i*/▼
#=1 /*the number of permutations (so far).*/
!.z=1;
w=max(length(z), length('permute'
say center('permutations for ' x ' things taken ' y " at a time",60,'═')
say
say pad 'permutation' center("permute", w, '─') "sign"
say pad '───────────' center("───────", w, '─') "────"
say pad center(#, 11) center(z , w) right(s, 4-1)
if _>2 then do;
z=overlay(
iterate
!.?=1;
end
end
return /*we're all finished with permutating. */</lang>
<pre>
══════permutations for 4 things taken 4 at a time═══════
|