Register to reply

Cyclic Permutation in C

by TheSourceCode
Tags: cyclic, permutation
Share this thread:
TheSourceCode
#1
Feb22-12, 11:39 PM
P: 14
Use nested for loops to produce the following pattern of cyclic permutations of the English
alphabet:
abcde......yz
bcdef......za
cdef......zab
...
zabcde......xy
HINT: you may find the modulo (remainder) operator % useful.

I have an idea of how to do this but it would not use the modulo operator. I thought of saving the first letter of an array into a variable, shifting everything else down one and putting it at the end. This also would only implement a single for loop. Any clues would be greatly appreciated.
Phys.Org News Partner Science news on Phys.org
Scientists discover RNA modifications in some unexpected places
Scientists discover tropical tree microbiome in Panama
'Squid skin' metamaterials project yields vivid color display
Joffan
#2
Feb23-12, 12:09 AM
P: 361
Yes, there are probably a million ways to do this, but I suggest that you have one loop generating the first character of each string and an inner loop (since that what was asked for) generating the successive letters of each string - using modulo operator to make the wrap from z to a.
TheSourceCode
#3
Feb23-12, 11:13 AM
P: 14
Thanks a lot. Took me a bit to get the wrap around to work properly but I got it. I don't think modulo was very intuitive to me before but now I get it.


Register to reply

Related Discussions
Prove product of infinite cyclic groups not an infinite cyclic group Calculus & Beyond Homework 3
Lagrangian formalism: cyclic coordinates. Why cyclic ? Where's the term come from? Classical Physics 0
Conjugation of a permutation by a permutation in a permutation group Calculus & Beyond Homework 3
Combinatorics - Finding all the four digit numbers with a property Precalculus Mathematics Homework 1
Differentiate between cyclic and non cyclic phosphorilation in photosynthesis? Biology 0