Cycles of a permutation: Difference between revisions
Minor code improvement.
(New post.) |
(Minor code improvement.) |
||
Line 144:
class Permutation {
public:
// Initialise the length of the strings to be permuted.
Permutation(uint32_t letters_size) : letters_count(letters_size) { }
// Return the permutation in one line form that transforms the string 'source' into the string 'destination'.
Line 188 ⟶ 190:
// Return the one line notation of the permutation given in cycle form.
const One_line cycles_to_one_line(Cycles& cycles) {
One_line one_line(
std::iota(one_line.begin(), one_line.end(), 1);
for ( uint32_t number = 1; number <=
for ( One_line& cycle : cycles ) {
const int32_t index = index_of(cycle, number);
Line 229 ⟶ 231:
Cycles combined_cycles;
std::unordered_set<uint32_t> used;
for ( uint32_t number = 1; used.size() <
if ( std::find(used.begin(), used.end(), number) == used.end() ) {
uint32_t combined = next(cycles_two, next(cycles_one, number));
Line 317 ⟶ 319:
}
const uint32_t
};
Line 348 ⟶ 350:
auto previous_day = [day_names] (const uint32_t& today) {
Permutation permutation(letters[0].length());
std::cout << "On Thursdays Alf and Betty should rearrange their letters using these cycles:" << std::endl;
|