Permutations: Difference between revisions
Content added Content deleted
m (→{{header|Ada}}) |
(→{{header|REXX}}: restructured the REXX program to use less space on RC. -- ~~~~) |
||
Line 2,036: | Line 2,036: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program |
<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,048: | Line 2,046: | ||
call permSets things,bunch,inbetweenChars,names |
call permSets things,bunch,inbetweenChars,names |
||
exit |
exit |
||
/*────────────────────────────────PERMSETS subroutine───────────────────*/ |
|||
⚫ | |||
⚫ | |||
/*──────────────────────────────────────────────────────────────────────*/ |
|||
⚫ | |||
⚫ | |||
@abcS=@abcU||@abc; @0abcS=123456789||@abcS |
|||
⚫ | |||
⚫ | |||
@abcu=@abc; upper @abcu |
|||
@abcs=@abcu||@abc |
|||
@0abcs=123456789||@abcs |
|||
@.='' |
|||
sep='' |
|||
do k=1 for x /*build list of symbols. */ |
do k=1 for x /*build list of symbols. */ |
||
_=p(word( |
_=p(word(uSyms,k) p(substr(@0abcS,k,1) k)) /*get or generate a symbol. */ |
||
if length(_)\==1 then sep='_' /*if not 1char, then use sep*/ |
if length(_)\==1 then sep='_' /*if not 1char, then use sep*/ |
||
$.k=_ /*append to the |
$.k=_ /*append to the symbol list.*/ |
||
end |
end |
||
if between=='' then between=sep /*use appropriate seperator.*/ |
if between=='' then between=sep /*use appropriate seperator.*/ |
||
list='$. @. between x y' |
list='$. @. between x y' |
||
call permset(1) |
call permset(1) |
||
exit |
exit |
||
/*────────────────────────────────PERMSET subroutine────────────────────*/ |
/*────────────────────────────────PERMSET subroutine────────────────────*/ |
||
permset: procedure expose (list); parse arg ? |
permset: procedure expose (list); parse arg ? |
||
if ?>y then do; _=@.1; do j=2 to y; _=_||between||@.j; end; say _; end |
|||
if ?>y then do |
|||
_=@.1 |
|||
do j=2 to y |
|||
_=_||between||@.j |
|||
end |
|||
say _ |
|||
end |
|||
else do q=1 for x /*construction permutation recursively*/ |
else do q=1 for x /*construction permutation recursively*/ |
||
do k=1 for ?-1 |
do k=1 for ?-1; if @.k==$.q then iterate q; end /*k*/ |
||
@.?=$.q; call permset(?+1) |
|||
end /*q*/ |
|||
@.?=$.q |
|||
call permset(?+1) |
|||
end |
|||
return |
return |
||
/*────────────────────────────────P subroutine (Pick one)───────────────*/ |
/*────────────────────────────────P subroutine (Pick one)───────────────*/ |
||
p: return word(arg(1),1)</lang> |
p: return word(arg(1),1)</lang> |
||
'''output''' when the following was used for input: <tt> 3 3 </tt> |
|||
<pre> |
<pre> |
||
123 |
123 |
||
Line 2,102: | Line 2,081: | ||
321 |
321 |
||
</pre> |
</pre> |
||
'''output''' when the following was used for input: <tt> 4 4 --- A B C D </tt> |
|||
<pre style="height:15ex;overflow:scroll"> |
<pre style="height:15ex;overflow:scroll"> |
||
A---B---C---D |
A---B---C---D |
||
Line 2,129: | Line 2,108: | ||
D---C---B---A |
D---C---B---A |
||
</pre> |
</pre> |
||
'''output''' when the following was used for input: <tt> 4 3 - aardvark gnu stegosaurus platypus </tt> |
|||
<br><br> |
|||
4 3 - aardvark gnu stegosaurus platypus |
|||
<pre style="height:15ex;overflow:scroll"> |
<pre style="height:15ex;overflow:scroll"> |
||
aardvark-gnu-stegosaurus |
aardvark-gnu-stegosaurus |