/* Returns a boolean which indicates whether it will be legal to assign
   num to the given row,col location. */
bool isSafe(int grid[N][N], int row, int col, int num)
{
    /* Check if 'num' is not already placed in current row,
       current column and current 3x3 box */
    return !UsedInRow(grid, row, num) &&
           !UsedInCol(grid, col, num) &&
           !UsedInBox(grid, row - row%3 , col - col%3, num);
}
示例#2
0
///\param puzzle The respective puzzle
///\param Row
///\param Column
///\param Number
int isSafe(int puzzle[SizeOfPuzzle][SizeOfPuzzle],int row,int col,int num){
    int x = boxLength(SizeOfPuzzle);

    /** Check if 'num' is not already placed in current row,
       current column and current box */
    if(UsedInRow(puzzle,row,num) == 0 && UsedInCol(puzzle,col,num) == 0 &&
       UsedInBox(puzzle,(row - row%x),(col - col%x),num) == 0) return 1;
    return 0;
}
示例#3
0
int isSafe(int sudoku[MAX_BOUNDS][MAX_BOUNDS], int row, int col, int num) 
{ 
    /* Check if 'num' is not already placed in current row, 
       current column and current 3x3 box */
    if (!UsedInRow(sudoku, row, num) && 
           !UsedInCol(sudoku, col, num) && 
           !UsedInBox(sudoku, row - row%3 , col - col%3, num)&& 
            sudoku[row][col]==UNASSIGNED)
    	return 1;
    return 0; 
} 
bool isSafe(int grid[N][N], int row, int col, int num)
{
    return !UsedInRow(grid, row, num) &&
           !UsedInCol(grid, col, num) &&
           !UsedInBox(grid, row - row%3 , col - col%3, num);
}