Problem 2085. Sudoku Solver - Standard 9x9
Solve a Standard 9x9 Sudoku. Values 1 thru 9 occur in each row, column, and the nine non-overlapping 3x3 matrices starting at the top left corner. Sudoku practice site.
Input: m, a 9x9 matrix of values 0 thru 9. Unknowns are 0s.
Output: mout, a 9x9 matrix of values 1 thru 9 that satisfy Sudoku rules.
Scoring: Time (msec) to solve the Hard Sudoku
Example:
m mout 390701506 398721546 042890701 542896731 106540890 176543892 820600150 829674153 400138009 457138269 031002087 631952487 065087304 965287314 703065920 713465928 204309075 284319675
Sudoku Variations:
Future challenges will involve the Sudoku variations Diagonal, Arrow(Sums), Inequality, Irregular, and others as they present themselves.
Algorithm Spoiler: Sudoku's can be readily solved using minimal choice recursion with consistency check. A key step is an index map of all indices that have mutual value exclusion (row,col,3x3), idxmap[81,27]. Another key step is to have an Evolve function that implements all single option values determined by the idxmap. A critical performance enhancement is a Sudoku Consistency Checker that checks for illegal replications of values. Illegal placements by Evolve occur when an incorrect value is asserted into the matrix during recursion trials. The recursive solver finds an idx with minimum options based on idxmap. The values for the idx location are asserted, Evolved, Consistency Checked, and then recursion call if Consistent. When all is Consistent and no unknowns remain the Sudoku is solved. Solution times are in the milli-seconds even for Evil, minimum 17 value, Sudokus.
Solution Stats
Problem Comments
-
2 Comments
This is a fun problem. Does the scoring based on time use no longer work?
i dont really get how the size of some problems is determined so small even though they have a really complex code when checking :/
took me like 3 hours to do, but it finally worked out,
definitely a challenge!!
Solution Comments
Show commentsProblem Recent Solvers37
Suggested Problems
-
Given two arrays, find the maximum overlap
1549 Solvers
-
Create a cell array out of a struct
2050 Solvers
-
609 Solvers
-
Put two time series onto the same time basis
326 Solvers
-
Test if two numbers have the same digits
243 Solvers
More from this Author308
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!