I need to figure out how to turn the 3x3 array
{{7,2,3}, {0,4,8}, {5,6,1}} into a 9x9 array where each 3x3 section is the original array o, but each value n is n+(9*c) where c is the corresponding section. In other words, section 0, 0 (top left) should have each of its values changed to originalValue+(9*7) since the top-left section of the original array is 7. Similar with the bottom-right, but the formula would be originalValue+(9*1) since the bottom-right section of the original array is 1. The new array should look like (just including the two sections mentioned)
{{70,65,66,0,0,0,0,0,0}, {63,67,70,0,0,0,0,0,0}, {68,69,64,0,0,0,0,0,0}, {00,00,00,0,0,0,0,0,0},//leading zeros added for easy legibility {00,00,00,0,0,0,0,0,0}, {00,00,00,0,0,0,0,0,0}, {0,0,0,0,0,0,16,11,12}, {0,0,0,0,0,0,09,13,17}, {0,0,0,0,0,0,14,15,10}} Now here is the hard part: I then need to repeat the process, but using this 9x9 array as the original array to get a 27x27 array, and then repeat it even more times to get a bigger array each time (81x81 then 243x243, etc.).
I have been able to get the method addAllValues() but I am stuck from going further.
public static int[][] addAllValues(int[][] data, int value2){ int value = value2 * 9; int[][] temp = data.clone(); int[][] newData = temp.clone(); for (int i = 0; i < temp.length; i++) { for (int j = 0; j < temp[0].length; j++) { newData[i][j] = temp[i][j] + value; } } return newData; } Can anyone help me with this? Thanks in advance!
Here is what I have tried:
public static int[][] gen(int amount) { if (amount == 0) { return normal; } else { int[][] newArray = gen(amount-1); int[][] temp = new int[newArray.length*3][newArray.length*3]; int[][][][] newArrays = {{addAllValues(newArray,7),addAllValues(newArray,2),addAllValues(newArray,3)},{addAllValues(newArray,0),addAllValues(newArray,4),addAllValues(newArray,8)},{addAllValues(newArray,5),addAllValues(newArray,6),addAllValues(newArray,1)}}; for (int i = 0; i < temp.length; i++) { for (int j = 0; j < temp.length; j++) { int x=0,y=0; if (0 <= i && i < 3){ x = 0; } else if (3 <= i && i < 6){ x = 1; } else if (6 <= i && i < 9){ x = 2; } if (0 <= j && j < 3){ y = 0; } else if (3 <= j && j < 6){ y = 1; } else if (6 <= j && j < 9){ y = 2; } temp[i] [j] = newArrays[x] [y] [i] [j]; } } return temp; } }