Emulation of C++ std::next_permutation:
Treats all permutations of seq as a set of "dictionary" sorted
sequences. Permutes the current sequence into the next one of this set.
Returns true if there are more sequences to generate. If the sequence
is the largest of the set, the smallest is generated and false returned.