Hello Im working on a Sudoku Checker which verifies the completed board’s solution is correct. I’m currently stumped on how to check within the blocks. right now I have a boolean as follows
where Im checking the upper left block (Block1). What I’m unsure about is what parameters to set it to and how to run the two for loops successfully.
The problem is that I want to check a section of a 2d array condensed too a 3×3 square and see if the integers in that area are not repeated that only 1-9 appear once. I have similar code in which i made this code that checks to see if a row has repeating integers and a column.
static boolean isBlock1Valid(int[][] sudokuBoard, int referenceRow, int referenceColumn)
{
for(int i =0; i<2;i++){
for(int j=0; j<2; j++){
if(sudokuBoard[i][j]==sudokuBoard[i][j])
return false;
}
}
return true;
}//end of isBlock1Valid
here is the row checker I used as reference to make the block checker
static boolean IsValidRow(int[][] sudokuBoard, int referenceRow, int width)
{
//Compare each value in the row to each other
for(int i = 0; i < width; i++)
{
for(int j = i+1; j < width; j++)
{
if(sudokuBoard[referenceRow][i] == sudokuBoard[referenceRow][j])
return false;
}
}
return true;
}
I’m not that quite sure what do you want you given code to do. But this method will always return false.
If you want make sure that there is only one instance of each element in one block. Then one soltuion would be to have a kind of checklist: