Anonymous user
Permutations: Difference between revisions
m
→names: put subroutines in alphabetical order, changed comments and indentation, added whitespace. -- ~~~~
m (→numbers: added whitespace, changed comments and indentation. -- ~~~~) |
m (→names: put subroutines in alphabetical order, changed comments and indentation, added whitespace. -- ~~~~) |
||
Line 2,507:
This program could be simplified quite a bit if the "things" were just restricted to numbers (numerals),
<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,513:
/* names (optional) defaults to digits (and letters). */
call permSets things, bunch, inbetweenChars, names
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────P subroutine (Pick one)─────────────*/▼
/*──────────────────────────────────.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.*/
Line 2,529 ⟶ 2,523:
@abcS = @abcU || @abc; @0abcS=123456789 || @abcS
do k=1 for x
_=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. */
Line 2,539 ⟶ 2,533:
call .permset 1
return
▲/*──────────────────────────────────.PERMSET subroutine─────────────────*/
▲/*──────────────────────────────────P subroutine (Pick one)─────────────*/
▲.permset: procedure expose (list); parse arg ?
▲p: return word(arg(1),1)</lang>
▲ @.?=$.q; call .permset ?+1
▲ end /*q*/
▲return</lang>
'''output''' when the following was used for input: <tt> 3 3 </tt>
<pre>
|