Permutations: Difference between revisions

Content added Content deleted
(updated faster D entry)
m (→‎version 1: changed name of internal subroutine, added whitespace, changed indentation. -- ~~~~)
Line 2,059: Line 2,059:
<br>but that would make it specific to numbers and not "things" or objects.
<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. */
<lang rexx>/*REXX program generates all permutations of N different objects. */

parse arg things bunch inbetweenChars names
parse arg things bunch inbetweenChars names


Line 2,067: Line 2,066:
call permSets things,bunch,inbetweenChars,names
call permSets things,bunch,inbetweenChars,names
exit /*stick a fork in it, we're done.*/
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 subroutine─────────────────*/
permSets: procedure; parse arg x,y,between,uSyms /*X things Y at a time.*/
permSets: procedure; parse arg x,y,between,uSyms /*X things Y at a time.*/
@.=; sep= /*X can't be > length(@0abcs). */
@.=; sep= /*X can't be > length(@0abcs). */
@abc='abcdefghijklmnopqrstuvwxyz'; @abcU=@abc; upper @abcU
@abc = 'abcdefghijklmnopqrstuvwxyz'; @abcU=@abc; upper @abcU
@abcS=@abcU||@abc; @0abcS=123456789||@abcS
@abcS = @abcU || @abc; @0abcS=123456789 || @abcS


do k=1 for x /*build a list of (perm) symbols.*/
do k=1 for x /*build a list of (perm) symbols.*/
_=p(word(uSyms,k) p(substr(@0abcS,k,1) k)) /*get or generate a symbol.*/
_=p(word(uSyms,k) p(substr(@0abcS,k,1) k)) /*get|generate a symbol.*/
if length(_)\==1 then sep='_' /*if not 1st char, then use sep. */
if length(_)\==1 then sep='_' /*if not 1st char, then use sep. */
$.k=_ /*append it to the symbol list. */
$.k=_ /*append it to the symbol list. */
end
end


if between=='' then between=sep /*use the appropriate seperator. */
if between=='' then between=sep /*use the appropriate seperator. */
list='$. @. between x y'
list='$. @. between x y'
call permset(1)
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 /*build permutation recursively. */
do k=1 for ?-1; if @.k==$.q then iterate q; end /*k*/
@.?=$.q; call permset(?+1)
end /*q*/
return
return
/*──────────────────────────────────P subroutine (Pick one)─────────────*/
/*──────────────────────────────────P subroutine (Pick one)─────────────*/
Line 2,156: Line 2,155:
platypus-stegosaurus-gnu
platypus-stegosaurus-gnu
</pre>
</pre>

===version 2===
===version 2===
This version is modeled after the Maxima program (as far as output).
This version is modeled after the Maxima program (as far as output).