Last active
May 18, 2018 12:55
-
-
Save ClassCubeGists/43385e3a5271113722adfa1a78400ab9 to your computer and use it in GitHub Desktop.
Solution to 2018 AP FRQ ArrayTester - https://clsc.be/27
This file contains 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 characters
public static int[] getColumn(int[][] arr2D, int c) { | |
int[] out = new int[arr2D.length]; | |
for (int r=0; r<arr2D.length; r++) | |
out[r] = arr2D[r][c]; | |
return out; | |
} |
This file contains 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 characters
public static boolean isLatin(int[][] square) { | |
int[] firstRow = square[0]; | |
if (containsDuplicates(firstRow)) | |
return false; | |
for (int r=1; r<square.length; r++) | |
if (!hasAllValues(firstRow, square[r])) | |
return false; | |
for (int c=0; c<square[0].length; c++) | |
if (!hasAllValues(firstRow, getColumn(square, c)) | |
return false; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment