I want to know if there is a way to start the iteration over std::next_permutation
somewhere other than the beginning. Is this possible?
I tried to change the starting string to the Nth lexographic permutation after a certain number of iterations, but doing that doesn't seem to work correctly, since for the following example it doesn't give 40320 permutations.
#include <algorithm>
#include <string>
#include <iostream>
#include <functional>
#include <vector>
#include <stack>
#include <unordered_set>
#include <chrono>
std::unordered_set<std::string> permutations;
int main()
{
auto start = std::chrono::high_resolution_clock::now();
std::string s="ABCDEFGH";
int partition = 5040;
int count;
std::string temp = s;
for (int i=0; i<8; i++)
{
count = 0;
temp = string_permutation((i*partition)+1,temp);
do
{
permutations.insert(temp);
} while(std::next_permutation(temp.begin(), temp.end()) && (++count != partition));
}
std::cout << permutations.size() << '\n';
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end - start;
std::cout << '\n' << diff.count() << " s\n";
}
where the string_permutation function I am using from here