https://github.com/alextanhongpin/opencv-sudoku
Experimenting sudoku solver with OpenCV
https://github.com/alextanhongpin/opencv-sudoku
algorithm-x computer-vision cv dancing-links opencv sudoku
Last synced: about 1 month ago
JSON representation
Experimenting sudoku solver with OpenCV
- Host: GitHub
- URL: https://github.com/alextanhongpin/opencv-sudoku
- Owner: alextanhongpin
- Created: 2018-08-31T16:25:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-10-03T16:14:51.000Z (over 3 years ago)
- Last Synced: 2025-01-29T21:52:40.942Z (3 months ago)
- Topics: algorithm-x, computer-vision, cv, dancing-links, opencv, sudoku
- Language: Jupyter Notebook
- Size: 10 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# opencv-sudoku
Experimenting sudoku solver with OpenCV## Dancing Links (DLX)
- also known as algorithm x
- is an exact cover problem
- attempts to find the all the rows of 1s, when merged, will have the full columns on 1s
- only works with 0s and 1s
- uses the toroidal data structure, which is basically a circular linked list that are linked from left to right, top to bottom.## Sudoku Solver
- uses the dancing links algorithm
- the fastest sudoku solver (?) - definitely faster than brute force attempt
- requires some modification - DLX only works on 1s and 0s, sudoku has numbers ranging from 1-9
- the sudoku constraints are converted into binary 1s and 0s to be used with DLX
- how to convert the numbers in sudoku to binary? Say we have number 9 at the uppermost top-left position (indicated by matrix `(i, j) = (0 ,0)`). Assuming that we can only have one unique number per row, then we have 81 possibilities. So we create an array of 81 zeros, and mark the position of the current number. For the number 9 in row 0 and column 0, the equivalent position is calculated by `row * 9 + val - 1` (minus 1, since the index starts from 0, but sudoku number starts from 1), which is index 8.
- there are four possible constraints - unique column, unique row, unique region, unique number in cell, which gives a total of `4 x 81`. This will be the size of the constraint matrix.