Last active
March 7, 2016 16:07
Revisions
-
poemdexter revised this gist
Mar 7, 2016 . 1 changed file with 9 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,12 @@ /* a 2D array can easily be represented by a standard array. given an array that has a size equal to a square number, reverse the order of the "rows" into a new array without changing the order of the elementes in each row. example: oldArray newArray row 1 [0,1,2 row 3 [6,7,8 row 2 3,4,5 --> row 2 3,4,5 row 3 6,7,8] row 1 0,1,2] */ int x = width; // known size int size = width * width; // always a square -
poemdexter created this gist
Mar 7, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ // oldArray newArray // 0,1,2 6,7,8 // 3,4,5 --> 3,4,5 // 6,7,8 0,1,2 int x = width; // known size int size = width * width; // always a square int[] newArray = new int[size]; for (int i = 0; i < width; i++) { for (int j = 0; j < width; j++) { int oldArrayPos = size - width * (i + 1); newArray[i * width + j] = oldArray[oldArrayPos + j]; } }