![]() ![]() When we find an empty cell, we pause and try to put all available numbers(1 – 9) in that particular empty cell. Our main recursive function(solve()) is going to just do a plain matrix traversal of the sudoku board. In each call to the recursive function, we just try all the possible numbers for a particular cell and transfer the updated board to the next recursive call. And the more correct way to try all possible solutions is to use recursion. Since we have to fill the empty cells with available possible numbers and we can also have multiple solutions, the main intuition is to try every possible way of filling the empty cells. Solutionĭisclaimer: Don’t jump directly to the solution, try it out yourself first. Let’s see how we can fill the cells below. There can exist many such arrangements of numbers. The empty cells are filled with the possible numbers. Note: Character ‘.’ indicates empty cell. Each 3×3 submatrix should be filled with numbers(1 – 9) exactly once. All the columns should be filled with numbers(1 – 9) exactly once.ģ. All the rows should be filled with numbers(1 – 9) exactly once.Ģ. Valid sudoku has the following properties.ġ. Given a 9×9 incomplete sudoku, solve it such that it becomes valid sudoku.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |