Anonymous user
Permutations: Difference between revisions
m
→version 1: changed name of internal subroutine, added whitespace, changed indentation. -- ~~~~
(updated faster D entry) |
m (→version 1: changed name of internal subroutine, added whitespace, changed indentation. -- ~~~~) |
||
Line 2,059:
<br>but that would make it specific to numbers and not "things" or objects.
<lang rexx>/*REXX program generates all permutations of N different objects. */
parse arg things bunch inbetweenChars names
Line 2,067 ⟶ 2,066:
call permSets things,bunch,inbetweenChars,names
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────.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 /*build permutation recursively. */▼
do k=1 for ?-1; if @.k==$.q then iterate q; end /*k*/▼
@.?=$.q; call .permset(?+1)▼
end /*q*/▼
return▼
/*──────────────────────────────────PERMSETS subroutine─────────────────*/
permSets: procedure; parse arg x,y,between,uSyms /*X things Y at a time.*/
@.=; sep= /*X can't be > length(@0abcs). */
@abc = 'abcdefghijklmnopqrstuvwxyz'; @abcU=@abc; upper @abcU
@abcS = @abcU || @abc; @0abcS=123456789 || @abcS
do k=1 for x /*build a list of (perm) symbols.*/
_=p(word(uSyms,k) p(substr(@0abcS,k,1) k)) /*get
if length(_)\==1 then sep='_'
$.k=_ /*append it to the symbol list. */
end
if between=='' then between=sep
list='$. @. between x y'
call .permset(1)
▲return
▲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 /*build permutation recursively. */
▲ do k=1 for ?-1; if @.k==$.q then iterate q; end /*k*/
▲ @.?=$.q; call permset(?+1)
▲ end /*q*/
return
/*──────────────────────────────────P subroutine (Pick one)─────────────*/
Line 2,156 ⟶ 2,155:
platypus-stegosaurus-gnu
</pre>
===version 2===
This version is modeled after the Maxima program (as far as output).
|