![]() ![]() #include #define SIZE 9 //sudoku problem int matrix = Python If there is no digit which fulfills the need, then we will just return false as there is no solution of this Sudoku. Else, we will come back and change the digit we used to fill the cell.Now, we will try to fill the next unallocated cell and if this happens successfully, then we will return true.Or else, we will fill an unallocated cell with a digit between 1 to 9 so that there are no conflicts in any of the rows, columns, or the 3x3 sub-matrices.If there are no unallocated cells, then the Sudoku is already solved.We are going to solve our Sudoku in a similar way. In backtracking, we first start with a sub-solution and if this sub-solution doesn't give us a correct final answer, then we just come back and change our sub-solution. Any 3x3 sub-matrix has the same number more than once.Any column contains the same number more than once.Any row contains the same number more than once.Thus, we can also conclude that a Sudoku is considered wrongly filled if it satisfies any of these criteria: You can see that every row, column, and sub-matrix (3x3) contains each digit from 1 to 9. For example, a Sudoku problem is given below. ![]() We are provided with a partially filled 9x9 matrix and have to fill every remaining cell in it. Sudoku is a 9x9 matrix filled with numbers 1 to 9 in such a way that every row, column and sub-matrix (3x3) has each of the digits from 1 to 9. If you don't know about backtracking, then just brush through the previous post. ![]() In this post, I will introduce a Sudoku-solving algorithm using backtracking. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |