Jump to content

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(LETTERS_COUNTletters_count);
std::iota(one_line.begin(), one_line.end(), 1);
for ( uint32_t number = 1; number <= LETTERS_COUNTletters_count; ++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() < LETTERS_COUNTletters_count; ++number ) {
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 LETTERS_COUNT = 15letters_count;
};
 
Line 348 ⟶ 350:
 
auto previous_day = [day_names] (const uint32_t& today) {
return ( day_names.size() + today - 1 ) % day_names.size();
};
 
Permutation permutation(letters[0].length());
 
std::cout << "On Thursdays Alf and Betty should rearrange their letters using these cycles:" << std::endl;
891

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.