Samchon Framework for CPP  1.0.0
PermutationGenerator.cpp
1 #include <samchon/library/PermutationGenerator.hpp>
2 
3 using namespace std;
4 using namespace samchon::library;
5 
6 PermutationGenerator::PermutationGenerator(size_t n, size_t r)
7  : super(n, r)
8 {
9  size_ = n;
10  for (size_t i = n - 1; i > n - r; i--)
11  size_ *= i;
12 
13  dividerArray.assign(n, NULL);
14  for (size_t i = 0; i < n; i++)
15  dividerArray[i] = i;
16 }
17 auto PermutationGenerator::operator[](size_t x) const -> vector<size_t>
18 {
19  vector<size_t> atoms = this->dividerArray;
20  vector<size_t> row(r_, NULL);
21 
22  for (size_t i = 0; i < row.size(); i++)
23  {
24  size_t item = x % atoms.size();
25  x = (size_t)floor(x / (double)atoms.size());
26 
27  row[i] = atoms[item];
28  atoms.erase(atoms.begin() + item);
29  }
30  return row;
31 }
auto n() const -> size_t
Get size of the N.
Definition: RWMutex.hpp:4
size_t size_
Size, the number of all cases.
Package of libraries.
Definition: library.hpp:84
size_t r_
R, size of elements of each case.
virtual auto operator[](size_t) const -> std::vector< size_t > override
Get x&#39;th case.
auto r() const -> size_t
Get size of the R.