permutation: Find All Permutations of Consecutive Integers

permutationR Documentation

Find All Permutations of Consecutive Integers

Description

Given an consecutive integer vector of length n, find all permutations of that vector.

Usage

find_all_permutations(n, init = 0L)

find_permutation_order(n, index = 1L, init = 0L)

find_permutation_index(order)

Arguments

n

an integer greater than 0

init

an integer indicating the initial starting value for the set of integers included in the permutation. See Details.

index

an integer between 1 and n indicatng which permutation to select (using R indexing rather than C indexing)

order

an integer vector indicating the response/permutation order that should be checked against

Details

init is useful for indexing C vs R code. If init = 0, then the indices will work with 0 indexed languages, such as C or Python. If init = 1, then the indices will work with 1 indexed languages, such as R.

Value

For find_all_permutations, a A matrix of size n! x n, where each row is a unique permutation. For find_permutation_order, the index row into the permutation matrix (where "index" uses R indexing). For find_permutation_index the index of the permutation matrix that leads to a particular order.

Note

find_permutation_order and find_permutation_index both use R indexing for determining the row in the permutation matrix and are almost inverses of each other. The reason they are "almost" inverses and not true inverses is because find_permutation_index needs only an integer vector and will standardize that vector to be between 1 and n. Therefore, the order is unique only up to a monotonic transformation.

Author(s)

Steven Nydick, steven.nydick@kornferry.com


swnydick/mupp documentation built on July 8, 2022, 7:59 a.m.