Problem
Write a program to solve a Sudoku puzzle by filling the empty cells.
Empty cells are indicated by the character
'.'.
You may assume that there will be only one unique solution.
Algorithm
Whenever we see a ".", guess a value from 1 to 9 and check if it violates the current row, column and sub-block. If it does not violate, guess next element. If all 9 numbers are tried and failed, this board cannot be solved. We need to roll back to previous position, therefore set current to be "." after iteration.
No comments:
Post a Comment