How can I rotate and flip the 2D char array so the letters display in different order?
char[,] array = new char[6,4] {
{ 'A', 'B', 'C', 'D' },
{ 'E', 'F', 'G', 'H' },
{ 'I', 'J', 'K', 'L' },
{ 'M', 'N', 'O', 'P' },
{ 'Q', 'R', 'S', 'T' },
{ 'U', 'V', 'W', 'X' }
};
6x4 Matrix
Orig. 90° 180° 270° Flip H Flip V
A B C D U Q M I E A X W V U D H L P T X D C B A U V W X
E F G H V R N J F B T S R Q C G K O S W H G F E Q R S T
I J K L W S O K G C P O N M B F J N R V L K J I M N O P
M N O P X T P L H D L K J I A E I M Q U P O N M I J K L
Q R S T H G F E T S R Q E F G H
U V W X D C B A X W V U A B C D
After the array has been rotated, I want to String.Join()
all the rows into a single line for another use.
So if you were to flip the array 90° and String.Join()
ABCDEFGHIJKLMNOPQRSTUVWX
would appears as UQMIEAVRNJFBWSOKGCXTPLHD
.
Example
Here is a rotation method 90°.
https://stackoverflow.com/a/42535/6806643
char[,] rotated = RotateMatrix(array, 4);
static char[,] RotateMatrix(char[,] matrix, int n) {
char[,] ret = new char[n, n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
ret[i, j] = matrix[n - j - 1, i];
}
}
return ret;
}
But I can only get it to display up to 4 columns
M I E A
N J F B
O K G C
P L H D
when it should be 6
U Q M I E A
V R N J F B
W S O K G C
X T P L H D