Skip to content

Instantly share code, notes, and snippets.

@ClassCubeGists
Last active May 18, 2018 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClassCubeGists/43385e3a5271113722adfa1a78400ab9 to your computer and use it in GitHub Desktop.
Save ClassCubeGists/43385e3a5271113722adfa1a78400ab9 to your computer and use it in GitHub Desktop.
Solution to 2018 AP FRQ ArrayTester - https://clsc.be/27
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;
}
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