Permutations: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: changed comments, added comments, added whitespace -- ~~~~)
m (→‎version 2: ordered subroutines in alphabetical order, alligned some statements, added whitespace. -- ~~~~)
Line 2,150: Line 2,150:
<br><br>It doesn't have the formatting capabilities of version 1, nor can it handle taking <math> X </math> items <math> Y </math> at-a-time.
<br><br>It doesn't have the formatting capabilities of version 1, nor can it handle taking <math> X </math> items <math> Y </math> at-a-time.
<lang rexx>/*REXX program shows permutations of N number of objects (1,2,3, ...).*/
<lang rexx>/*REXX program shows permutations of N number of objects (1,2,3, ...).*/
arg n .; if n=='' then n=3 /*Not specified? Assume default*/
parse arg n .; if n=='' then n=3 /*Not specified? Assume default*/
/*populate the first permuatation*/
/*populate the first permuatation*/
do pop=1 for n; @.pop=pop ; end; call tell n
do pop=1 for n; @.pop=pop ; end; call tell n
do while nextperm(n,0); call tell n; end
do while nextperm(n,0); call tell n; end
exit /*stick a fork in it, we're done.*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────NEXTPERM subroutine─────────────────*/
/*──────────────────────────────────────────────────────────────────────*/
tell: procedure expose @.; _=; do j=1 for arg(1);_=_ @.j;end; say _;return
/*──────────────────────────────────────────────────────────────────────*/
nextperm: procedure expose @.; parse arg n,i; nm=n-1
nextperm: procedure expose @.; parse arg n,i; nm=n-1


Line 2,169: Line 2,167:
do j=i+1 while @.j<@.i; end
do j=i+1 while @.j<@.i; end
parse value @.j @.i with @.i @.j
parse value @.j @.i with @.i @.j
return 1</lang>
return 1
/*──────────────────────────────────TELL subroutine─────────────────────*/
tell: procedure expose @.; _=; do j=1 for arg(1);_=_ @.j;end; say _;return</lang>
'''output'''
'''output'''
<pre style="overflow:scroll">
<pre style="overflow:scroll">