If you make your variable names short enough, you can just make them an all-lowercase string [a-z0-9]+ and not worry about CamelCase or underscores or minuses

If you name your variables things like x, y, c, i, eu, ev, gorp, then you don't have to worry about CamelCase

@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...)

Follow

@vaporeon_ when i looked at other solutions people usually used a greatest common denominator algorithm which is O(sqrt(n)) in this step, but the reasons for it are due to Math I Don't Understand

@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

@vaporeon_ "cycle" is not a technical concept it is a word i made up to describe what i was looking for

@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

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.