Jump to content

Permutations/Rank of a permutation: Difference between revisions

m
{{out}}
(Promote from draft to full task status.)
m ({{out}})
Line 1:
{{task}}
A particular ranking of a permutation associates an integer with a particular ordering of all the permutations of a set of distinct items. For our purposes the ranking will assign integers <math>0 .. (n! - 1)</math> to an ordering of all the permutations of the integers <math>0 .. (n - 1)</math>.
For our purposes the ranking will assign integers <math>0 .. (n! - 1)</math> to an ordering of all the permutations of the integers <math>0 .. (n - 1)</math>.
 
For example, the permutations of the digits zero to 3 arranged lexicographically have the following rank:
Line 121 ⟶ 122:
</lang>
 
{{out}}
And here's the output:
 
<pre> 0: [ 1, 2, 3, 0 ] = 0
1: [ 3, 2, 0, 1 ] = 1
Line 501:
}</lang>
 
{{out}}
'''Output:'''
 
<pre>0 --> [0, 1, 2] --> 0
1 --> [0, 2, 1] --> 1
Line 672 ⟶ 671:
test2('First ordering, large number of perms:', unranker1)</lang>
 
{{out}}
;Sample output:
<pre>First ordering:
From rank 0 to [1, 2, 0] back to 0
Line 779 ⟶ 778:
(factorial (length xs))))]))
</lang>
{{out}}
Example and output:
<langpre>
(for/list ([n 24])
(define p (perm '(0 1 2 3) n))
Line 809 ⟶ 808:
(22 (3 2 0 1) 22)
(23 (3 2 1 0) 23))
</langpre>
 
=={{header|REXX}}==
Line 815 ⟶ 814:
this modified version starts the permute numbers with 0 (zero) instead of 1.
 
Since this REXX program generates permutations without recursive calls, testing for the limit for a ''stack overflow'' wouldn't be
testing for the limit for a ''stack overflow'' wouldn't be possible using this REXX program.
<lang rexx>/*REXX program shows permutations of N number of objects (1,2,3, ...).*/
parse arg N seed .; if N=='' then N=3 /*Not specified? Assume default*/
Line 850 ⟶ 849:
do j=q+1 while @.j<@.q; end; parse value @.j @.q with @.q @.j
return 1</lang>
'''output'''{{out}} when using the default input
<pre style="overflow:auto;height:250px">
4 items, permute 0 = 0 1 2 3 rank= 0
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.