// Manipulations with double dimension arrays
1
2 //equate two arrays
3 private static boolean isEqual(char [][]arr1, char [][]arr2) {
4 if(arr1.length!=arr2.length) return false;
5 boolean res = true;
6 for(int i=0; i<arr1.length; i++) {
7 res = res & Arrays.equals(arr1[i], arr2[i]);
8 }
9 return res;
10 }
11
12 //rotate clockwise 90 degrees
13 private static char [][]rotate90(char [][]arr) {
14 char [][]ret = new char[arr.length][arr[0].length];
15 for(int j=0; j<arr[0].length; j++) {
16 for(int i=0; i<arr.length; i++) {
17 ret[i][j] = arr[j][i];
18 }
19 }
20 //print(ret);
21 return reflect(ret);
22 }
23
24 //reflect horizontally
25 private static char [][]reflect(char [][]arr) {
26 char [][]ret = new char[arr.length][arr[0].length];
27 for(int i=0; i<arr.length; i++) {
28 for(int j=0; j<arr[0].length; j++) {
29 ret[i][j] = arr[i][arr[i].length-j-1];
30 }
31 }
32 //print(ret);
33 return ret;
34 }
35
36 //prints for debugging
37 private static void print(char [][]arr) {
38 for(int i=0; i<arr.length; i++) {
39 System.out.println(Arrays.toString(arr[i]));
40 }
41 System.out.println();
42 }