getpermutation {TUGLab} | R Documentation |
Get permutation
Description
Given a number of players and a position, this function returns the permutation of players that occupies the given position when permutations are arranged according to the Lehmer code.
Usage
getpermutation(n, pos)
Arguments
n |
Number of players, as an integer. |
pos |
Position according to the Lehmer code, as an integer. |
Details
The Lehmer code makes use of the fact that there are n!
permutations of a sequence of n
numbers.
If a permutation \sigma
is specified by the sequence (\sigma_{i})_{i=1}^{n}
, its Lehmer code is the
sequence L(\sigma)=(L(\sigma)_{i})_{i=1}^{n}
, where L(\sigma)_i=|\{j>i:\sigma_j<\sigma_i\}|
.
The position of permutation \sigma
according to the Lehmer code order is
L_{\sigma}=1 + \sum_{i=1}^{n} (n-i)! L(\sigma)_i
.
Value
The permutation of n
players whose Lehmer code position is pos
, as a vector.
See Also
Examples
getpermutation(4, 5)
n <- 4
for (i in 1:factorial(n)) {
cat("[", i, "]", paste(getpermutation(n,i)), "\n")
}