Latin square logic

• November 20th, 2010, 06:09 PM
Deprogrammer
Latin square logic
I am trying to test the logic of a particular method included in a project I am working on and so I have created a simple 3 by 3 Latin Square with which to do so. The basics of the program work fine, printing the board, entering numbers, determining when the grid is full and son on. However, the method that evaluates the values actually contained within the squares of the grid. To do so, I drew up a Boolean method which contains a series of nested loops to test the numbers against each other. The desired result would be to have the Boolean variable "checkValue" read true when the game has been won - that is when each row contains a unique value from 1 to 3 and likewise the columns. The grid is a mutli-dimensional array named "board" nad x and y are of course the horizontal and verticle coordinates. Here is my code:
Code Java:

```public boolean check() { for (int x = 0; x < n; x++) { for (int y = 0; y < n; y++) {   // Check row for (int i = 0; i < n; i++) { if (board[x][i] != board[x][y]) checkValue = true; }   // Check column for (int i = 0; i < n; i++) { if (board[i][y] != board[x][y]) checkValue = true; } } } return checkValue; }```
• November 20th, 2010, 10:57 PM
Darryl.Burke
Re: Latin square logic
You need to return false as soon as a clash is found, and return true after all checks have passed. Pseudocode:
Code :

```boolean someMethod() { for outer loop for inner loop if some condition is not met return false end if end for end for return true }```
db
• November 21st, 2010, 08:38 AM
Deprogrammer
Re: Latin square logic