@vaporeon_
The downside of doing that is that your code starts looking like this:
class Solution {
public:
int p(int i, int l, int s) {
return (s + i) % l;
}
int swap(vector<int>& a, int i, int j) {
int t = a[i];
a[i] = a[j];
a[j] = t;
return j;
}
void rotate(vector<int>& n, int k) {
int L = n.size();
k = k % L;
int c = 1;
while ((c * k) % L != 0) c++;
for (int i = 0; i < L / c; i++)
for (int j = 1, b = i, D = L - k; j < c; j++)
b = swap(n, b, p(b, L, D));
}
};
@wallhackio I don't see the problem (why would you name an array of integers n
, though? That's traditionally reserved for the size/length of an array or a matrix!)
(Also, is while ((c * k) % L != 0) c++;
really the only way to find a c
such that (c * k) % L == 0
? The repeated multiplication sounds very inefficient, but my brain doesn't want to do maths right now...)
@vaporeon_ what i'm trying to do is find the length of a "cycle" in the array. a cycle is the number of "jumps" you can do in the array if you jump forward by a set number of indices before you return to where you started, assuming that you start back at the beginning of the array once you exceed its length
@wallhackio I think that when our lecturer was explaining some similar concept (how many times you can perform an operation before you end up at the beginning again) in elliptic-curve cryptography, they called it a "cycle", too
So I think that's a very reasonable word for it
@vaporeon_ "cycle" is not a technical concept it is a word i made up to describe what i was looking for