### [17-08-21] Challenge #328 [Easy] Latin Squares

Converts input to 2D char array, checks that all columns and rows sum to the same value, because if each row and column has only one instance of each character while still containing all possible unique characters, the only way they can all sum to the same value is if input is a valid square.

Is this a stupid solution?

``````public class LatinSquares {
public static void main(String[] args) {
/* arg[0] is # symbols, remainder of args is symbols */
int symbolCount = Integer.parseInt(args[0]);
char[][] latinSquare = new char[symbolCount][symbolCount];
boolean isSquare = true;

/* convert to square */
int row = 0;
for(int i = 1; i < args.length; i++) {
if(i > 1 && (i - 1) % symbolCount == 0) row++;
latinSquare[row][i % symbolCount] = args[i].charAt(0);
}

/* determine if square */
int sum = rowSum(latinSquare, 0);
for(int i = 0; i < latinSquare.length; i++) {
if(rowSum(latinSquare, i) != sum || colSum(latinSquare, i) != sum) {
isSquare = false;
break;
}
}
System.out.println(isSquare);
}

public static int rowSum(char[][] latinSquare, int row) {
int sum = 0;
for(int col = 0; col < latinSquare[row].length; col++) {
sum += latinSquare[row][col];
}
return sum;
}

public static int colSum(char[][] latinSquare, int col) {
int sum = 0;
for(int row = 0; row < latinSquare.length; row++) {
sum += latinSquare[row][col];
}
return sum;
}
}
``````