I have a matrix that I am trying to "count" through by shifting the first row to the left n number of times until it is in its original position, at which point I would shift the second row to the left once, then go through the entire first row again, shift the second row once, so on and so forth until the second row is in its original position, at which point the third row would shift once and we start all over again.
For example:
0 1 2 1 2 0 2 0 1 0 1 2 1 2 0 2 0 1 a few 0 1 2 1 2 0
0 1 2 ==> 0 1 2 ==> 0 1 2 ==> 1 2 0 ==> 1 2 0 ==> 1 2 0 ==> ==> ==> 0 1 2 ==> 0 1 2 ... ... ...
0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 more 1 2 0 1 2 0
all the way until every possible combination has been reached. In an MxN matrix this should give me N^M possibilities. The actual matrix I am working with is much larger than this one so I am trying to avoid 250+ nested loops.
I already have the shift method:
static inline void shift(uint8_t *row){ //a row from a 2D Array
int a, temp;
int b = sizeof(row);
temp = row[0];
for(a = 0; a < b; a++){
channel[a] = channel[a+1];
}
channel[b] = temp;
}
Any help would be greatly appreciated.
int b = sizeof(row);is not correct.rowis a pointer, you cannot know its size. You must pass the size of the row as a separate parameter to the function. - Luca Politorow(it is the size of a pointer), but it is unrelated to the number of elements in the row. - William Pursell