Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Sudoku is a number placement puzzle: a 9 x 9 grid made up of 3 x 3 subgrids. Som

ID: 665708 • Letter: S

Question

Sudoku is a number placement puzzle: a 9 x 9 grid made up of 3 x 3 subgrids. Some cells already contain numbers, known as "givens", for example: 5 3 1 9 5 9 8 2 8 4 1 9 The goal is to fill in the empty cells, one number in each, so that each column, row, and subgrid contains the numbers 1-9 exactly once. A player often needs to determine which numbers can be placed in a particular cell location. Given a partially filled game grid with 0s for empty cells, a public boolean findPossible(int rid, int i, int j) that returns a 9-element boolean array indicating whether each number is possible in the cell ith across and jth down from the top left corner (0,0). For example, if 1 is possible at the specified location, the first element of the boolean array should be true, otherwise false. Factor out the subtasks into separate methods to make your code easier to understand.

Explanation / Answer

public bool isSolution()
{
if (isComplete() && isRowCheckUnique() && isColCheckUnique() && isCubeUnique())
{
return true;
}
return false;
}


public bool isComplete()
{
for (int i = 0; i <= (N * N)-1; i++)
{
for (int j = 0; j <= (N * N)-1; j++)
{
if (!(board[i, j] <= 9 && board[i, j] >= 1))
{
return false;
}
}
}
  
return true;
}

public bool isRowCheckUnique()
{
for (int i = 0; i <= (N * N)-1; i++)
{
for (int j = 0; j <= (N * N)-1; j++)
{
//checkValue[0] = true;
  
if (checkValue[board[i,j]] == true)
{
checkValue[board[i,j]] = false;
}
else
{
return false;
}
}
for (int k = 0; k <= 9; k++)
{
checkValue[k] = true;
}
}
  
return true;
}

//values in columns is unique? use check value array for true or false
public bool isColCheckUnique()
{
for (int i = 0; i <= (N * N)-1; i++)
{
for (int j = 0; j <= (N * N)-1; j++)
{
if (checkValue[board[i,j]] == true)
{
checkValue[board[i,j]] = false;
}
else
{
return false;
}
}
for (int k = 0; k <= 9; k++)
{
checkValue[k] = true;
}
}
  
return true;
}


public bool isCubeUnique()
{
#region iscubeunique
//1,1
for (int i = 0; i <= 2; i++)
{
for (int j = 0; j <= 2; j++)
{
checkValue[0] = true;
  
if (checkValue[board[i, j]] == true)
{
checkValue[board[i, j]] = false;
}
else
{
return false;
}
}   
}
for (int k = 0; k <= 9; k++)
{
checkValue[k] = true;
}
//1,2
for (int i = 0; i <= 2; i++)
{
for (int j = 3; j <= 5; j++)
{
checkValue[0] = true;
  
if (checkValue[board[i, j]] == true)
{
checkValue[board[i, j]] = false;
}
else
{
return false;
}
}   
}
for (int k = 0; k <= 9; k++)
{
checkValue[k] = true;
}
  
//1,3
for (int i = 0; i <= 2; i++)
{
for (int j = 6; j <= 8; j++)
{
checkValue[0] = true;
  
if (checkValue[board[i, j]] == true)
{
checkValue[board[i, j]] = false;
}
else
{
return false;
}
}
}
for (int k = 0; k <= 9; k++)
{
checkValue[k] = true;
}
//2,1
for (int i = 3; i <= 5; i++)
{
for (int j = 0; j <= 2; j++)
{
checkValue[0] = true;
  
if (checkValue[board[i, j]] == true)
{
checkValue[board[i, j]] = false;
}
else
{
return false;
}
}
}
for (int k = 0; k <= 9; k++)
{
checkValue[k] = true;
}
//2,2
for (int i = 3; i <= 5; i++)
{
for (int j = 3; j <= 5; j++)
{
checkValue[0] = true;
  
if (checkValue[board[i, j]] == true)
{
checkValue[board[i, j]] = false;
}
else
{
return false;
}
}   
}
for (int k = 0; k <= 9; k++)
{
checkValue[k] = true;
}
//2,3
for (int i = 3; i <= 5; i++)
{
for (int j = 6; j <= 8; j++)
{
checkValue[0] = true;
  
if (checkValue[board[i, j]] == true)
{
checkValue[board[i, j]] = false;
}
else
{
return false;
}
}   
}
for (int k = 0; k <= 9; k++)
{
checkValue[k] = true;
}
//3,1
for (int i = 6; i <= 8; i++)
{
for (int j = 0; j <= 2; j++)
{
checkValue[0] = true;
  
if (checkValue[board[i, j]] == true)
{
checkValue[board[i, j]] = false;
}
else
{
return false;
}
}   
}
for (int k = 0; k <= 9; k++)
{
checkValue[k] = true;
}
//3,2
for (int i = 6; i <= 8; i++)
{
for (int j = 3; j <= 5; j++)
{
checkValue[0] = true;
  
if (checkValue[board[i, j]] == true)
{
checkValue[board[i, j]] = false;
}
else
{
return false;
}
}   
}
for (int k = 0; k <= 9; k++)
{
checkValue[k] = true;
}
//3,3,
for (int i = 6; i <= 8; i++)
{
for (int j = 6; j <= 8; j++)
{
checkValue[0] = true;
  
if (checkValue[board[i, j]] == true)
{
checkValue[board[i, j]] = false;
}
else
{
return false;
}
}   
}
for (int k = 0; k <= 9; k++)
{
checkValue[k] = true;
}
  
return true;
#endregion
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote