Comparing integers in a certain block Sudoku Java
Question
So i've update my code and im still stumped on how to check a 3x3 block within a completed sudoku board to see if it doesn't have any repeating numbers. this is my method that i've updated.
static boolean isBlock1Valid(int[][] sudokuBoard, int referenceRow, int referenceColumn)
{
boolean[] seen = new boolean[9];
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
if ( seen(sudokuBoard[referenceColumn+i][referenceRow+j])) return false;
else ( seen(sudokuBoard[referenceColumn+i][referenceRow+j])) = true;
}
}
return true;
}//end of isBlock1Valid
this is the calling method i don't know which parametrs to send to the method isBlock1Valid
public static void Validate(final int[][] sudokuBoard)
{
int width = sudokuBoard[0].length;
int height = sudokuBoard.length;
for(int i = 0; i < width; i++)
if(!IsValidRow(sudokuBoard, i, width))
{
System.out.print("Invalid entry found \n (Row)" + "\t"+ i + "\n");
//Do something - The row has repetitions
}
else{
System.out.print("Row " +i + " is valid \n");
}
for(int j = 0; j < height; j++)
if(!IsValidColumn(sudokuBoard, j, height))
{
System.out.print("(Column)" + j + "\n");
//Do something - The columns has repetitions
}
else{
System.out.print("Column " +j +" is valid \n");
}
for(int i=0; i<2; i++)
if(!IsBlock1Valid(sudokuBoard,i, j)){
System.out.print("hi");
}
}
Solution
Accessing a cell in an array should be using square brackets, and seen
is an array:
seen[sudokuBoard[referenceColumn+i][referenceRow+j]]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow