c++ - Sudoku solver finding a solution for unsolvable sudoku -


I wrote a sudoku solver and sudoku is solvable when it works fine. However, when Sudoku is incompatible, then it changes the original number of the puzzle when the back tracking is done.

  bool: Sudoku :: sol (int row, int col) {if (board [row] [col]! = 0) {int next_col = col; Int next_row = Row; Next_col ++; If (next_col> 8) {next_row ++; Next_col = 0; } If (next_row> 8) {Back to true; } And {if (the solution (next_row, next_col)) is true; }} For (int number = 1; number & lt; = 9; numbers ++) {board [row] [col] = number; If (check_ro (line, number) & amp; amp; and check_cl (call, number) & check_box (line, call, number)) {int next_row = row; Int next_col = col + 1; If (next_col> 8) {next_col = 0; Next_row ++; } If (next_row> 8) {Back to true; } If (solution (next_row, next_col)) is true; }} Board [row] [color] = 0; return false;   

}

The board is a 2D int array. I know that I can use any type of structure rather than integer, which will store if the number is present or not, but this solution is not actually appealing to me, is there any other The way?

In the beginning, when the cell is set,

  If (board [row] [col]! = 0) {int next_col = col; Int next_row = Row; Next_col ++; If (next_col> 8) {next_row ++; Next_col = 0; } If (next_row> 8) {Back to true; } And {if (the solution (next_row, next_col)) is true; }}   

Add one

  else {return false; }   

or last

  Resolve return (next_row, next_col);   

To avoid changing the given numbers, as if the puzzle can not be solved - the original solution should be solved even after the previous cell is guessed incorrectly. It can walk happily to change the number in the cell.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -