- Home /
Need Equation to flip 5x5 Matrix
On a wing and a prayer here ... does anyone know of a way to flip the values below?
An equation where 2 becomes 14, 3 becomes 13, 4 becomes 12, etc?
So, want to switch row 0 with row 4, and row 1 with row 3?
If so, that's super-easy. Just a single loop and swap A[i][0] with A[i][4].
hmm cool, I was hoping for something more elegant but that should work. Though I think I am going to just make a huge Switch/Case ins$$anonymous$$d of 4 arrays. Thanks tho!
If you can handle the program$$anonymous$$g, a 2-dimensional array is much better. In C# something like int[,] = new int[5,5];
. Do you just have 25 variables, now?
With large ifs/switches it's so easy to have one tiny mistake -- position 2,4 swaps with 2,2 ins$$anonymous$$d of 2,1 -- which doesn't show up in testing. Loops over arrays either break big-time, or work perfectly. Plus much easier to go to a 6x6 board.