Created
November 27, 2018 13:42
Star
You must be signed in to star a gist
Working solution for the 2018 AP Computer Science ArrayTester Free Response question https://compsci.rocks
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