Anonymous user
Permutations: Difference between revisions
m
→{{header|REXX}}: changed comments, added comments, added whitespace -- ~~~~
m (→{{header|REXX}}: changed comments, added comments, added whitespace -- ~~~~) |
|||
Line 2,056:
call permSets things,bunch,inbetweenChars,names
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────PERMSETS subroutine─────────────────*/
permSets: procedure; parse arg x,y,between,uSyms /*X things Y at a time.*/
@.=; sep=
@abc='abcdefghijklmnopqrstuvwxyz'; @abcU=@abc; upper @abcU
@abcS=@abcU||@abc; @0abcS=123456789||@abcS
if between=='' then between=sep
list='$. @. between x y'
call permset(1)
return
/*──────────────────────────────────PERMSET subroutine──────────────────*/
permset: procedure expose (list); parse arg ?
if ?>y then do; _=@.1; do j=2 to y; _=_||between||@.j; end; say _; end
else do q=1 for x /*
do k=1 for ?-1; if @.k==$.q then iterate q; end /*k*/
@.?=$.q; call permset(?+1)
end /*q*/
return
/*──────────────────────────────────P subroutine (Pick one)─────────────*/
p: return word(arg(1),1)</lang>
'''output''' when the following was used for input: <tt> 3 3 </tt>
<pre>
Line 2,152:
arg n .; if n=='' then n=3 /*Not specified? Assume default*/
/*populate the first permuatation*/
do pop=1 for n;
do while nextperm(n,0); call tell n; end
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────────────────────────────────────────*/
tell: procedure expose @.; _=; do j=1 for arg(1);_=_ @.j;end; say _;return
/*──────────────────────────────────────────────────────────────────────*/
nextperm: procedure expose @.; parse arg n,i; nm=n-1
do k=nm by -1 for nm; kp=k+1
Line 2,167:
if i==0 then return 0
do j=i+1 while @.j<@.i; end▼
▲ do j=i+1 while @.j<@.i; end
parse value @.j @.i with @.i @.j
return 1</lang>
'''output'''
<pre style="
1 2 3
1 3 2
|