Quote (AbDuCt @ Apr 30 2013 03:00am)
pretty much.
you take 2 arrays of the same size lets say
1 2 3 4
4 5 6 7
8 9 10 11
in the new array you would take array[0][0] and place it to newarray[3][0]
then you would increment your collum and set array[0][1] to newarray[3][1]
or something similiar to that. to tired to explain it thoroughly
This is right. I was also too tired last night (and frustrated!) to give it a valid explanation. I'll give you what I have so far, but being stumped it is not working. I think I could come up with a "working" but rather bulky solution. I have googled and found examples where they do it with 2 for loops but I can't seem to replicate it properly.
Here is my code: (I drew a picture in there to try to help me figure it out. The "DIMENSION" is a global constant which would be 4 in this case though the array is indexed 0-3. Another note is that my current work is based off of an example that doesn't appear correct at all "DIMENSION - col - 1" to generate the new row value.
Code
* Scrambles the grid by rotating it 90 degrees clockwise, whereby
* grid[0][0] rotates to grid[0][DIMENSION - 1].
*
*ex.
* 1 2 3 4 1 2 3 4
*
* 1: 1,1 1,2 1,3 1,4 4,1 3,1 2,1 1,1
* 2: 2,1 2,2 2,3 2,4 4,2 3,2 2,2 1,2
* 3: 3,1 3,2 3,3 3,4 4,3 3,3 2,3 1,3
* 4: 4,1 4,2 4,3 4,4 4,4 3,4 2,4 1,4
* column -> row
row -> (DIMENSION - column - 1)? [ 1,1 ] -> [ 4, 1]
*
*/
void scramble(void)
{
char tempGrid[DIMENSION][DIMENSION];
for(int row = 0; row < DIMENSION; ++row)
{
for(int col = 0; col < DIMENSION; ++col)
{
tempGrid[row][col] = grid[DIMENSION - col - 1][row];
}
}
grid = tempGrid;
}
Here is where I was looking for examples previously:
http://stackoverflow.com/questions/42519/how-do-you-rotate-a-two-dimensional-arrayhttp://stackoverflow.com/questions/2893101/how-to-rotate-a-n-x-n-matrix-by-90-degreesThe second one takes a bit of a different approach. I saw one example where they said each "layer" further away from the center would need some different math and I think that is the case, I just have to find the relation and have failed thus far. I am about to take another look at it today and will update when I figure it out, so till then help!