Returns the permutation of the given rank, as generated by the Permutation Class 2 component.

View versions (1)

Interface

#include <codecogs/maths/combinatorics/permutations/unrank.h>

using namespace Maths::Combinatorics::Permutations;

This function computes the permutation of given rank and size, as generated by the <em> Permutation Class 2 </em> component, but <em> without </em> generating all the previous permutations. This function may be used with the Rank component in order to give a method of recognizing certain permutations only by their rank number.

Example:

#include <codecogs/maths/combinatorics/permutations/unrank.h>
#include <iostream>
int main()
{
  std::cout << "The permutation of 10 elements and rank 124 is:";
  std::cout << std::endl;
  std::vector<int> result = Maths::Combinatorics::Permutations::unrank(10, 124);
  for (int i = 0; i < result.size(); i++)
    std::cout << result[i] << "  ";
  std::cout << std::endl;
  return 0;
}

Output:

The permutation of 10 elements and rank 124 is:
1  2  3  9  4  5  10  6  8  7

References

SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html

Returns

the permutation of size n and given rank, as generated by the <em> Permutation Class 2 </em> component
GPL Licence — free for non commercial use. See Licence details.