5
I need to create a C algorithm to rotate a 10x10 matrix by 90 degrees, however I cannot use an auxiliary matrix for this.
Simplifying what was asked to try to find some pattern and use it to solve the problem I used a 3x3 matrix and compared in a table the position that each element occupies in the original matrix and that will occupy in the rotated matrix.
ORIGINAL | ROTACIONADA
0x0 0x1 0x2 | 0x2 1x2 2x2
1x0 1x1 1x2 | 0x1 1x1 2x1
2x0 2x1 2x2 | 0x0 1x0 2x0
You can notice a pattern in which for the original matrix the value of the line remains constant at each cycle of 3 positions and the value of the column is added at 1 in the same cycle. For the rotated version of the matrix the row and column values correspond respectively to the column and row.
Despite that I do not know how to take advantage of this information, since transferring the values to the positions corresponding to the rotated version will lose values that I will still use.
For example:
Transferring the value from 0X0 to 2X0 will lose the original 2x0 content that would need to transfer to 2x2 later.
What have you done? And you don’t need an extra matrix, just an auxiliary variable inside a for...
– Felipe Avelar
In fact what I was able to do was just the previous reasoning, I could not make an algorithm precisely by limiting the loss of content. And as for the auxiliary variable I did some tests and I realized that I would need many "auxiliary variables", because in each cycle of three positions I need to save three values for the next cycles.
– Vinicius
Dude, I edited your question to try to make it more visual with a 3x3 matrix, I could check if that’s what should really happen?
– Felipe Avelar
That’s exactly what should happen. Thank you!
– Vinicius
Dude, the logic is pretty simple, you’re going to have to change the value between 4 positions, all of which follow a very simple logic. I’m kind of running now, but then I publish the answer. (:
– Felipe Avelar
I’ll post a possible response, if you really need to change the matrix let me know that I complete.
– DaviAragao