Fast Sudoku Solver

버전 1.0.0.0 (1.68 KB) 작성자: Michael Kleder
Rapidly finds all possible solutions to a sudoku puzzle
다운로드 수: 5.4K
업데이트 날짜: 2006/12/28

라이선스 없음

SUDOKU - rapidly find all possible solutions to a sudoku puzzle

Usage: Mout = sudoku(M)

M = intial sudoku matrix, with zeros for empty entries
Mout = solution as a 9x9 matrix if there is a unique solution, or as a 9x9xN matrix if there are N solutions

Notes:
(1) The algorithm employs recursion, but does as much as it can with straighforward deterministic deduction at each recursion level to increase overall speed.
(2) Supplying this function with an empty or overly sparse input matrix can create longer calulation times as the function searches for all possible solutions.
(3) A "No solution" error is generated if the input puzzle has no valid solution.
(4) Tested but no warranty, use at your own risk.
(5) Michael Kleder, December 2006

Examples:

% find the unique solution to this puzzle in a fraction of a second:
M = [0 0 8 0 9 0 5 0 0;0 0 1 0 7 0 4 0 0;0 0 4 0 3 0 6 0 0;
0 1 0 0 0 6 0 0 7;0 9 0 0 0 3 0 0 0;0 2 0 0 5 0 0 6 0;
0 5 0 0 4 0 0 2 0;0 0 0 8 0 0 0 3 0;6 0 0 1 0 0 0 4 0];
sudoku(M)

% find the 100 possible solutions to this puzzle in few seconds:
M = [0 0 8 0 9 0 5 0 0;0 0 1 0 7 0 0 0 0;0 0 4 0 3 0 6 0 0;
0 1 0 0 0 0 0 0 7;0 9 0 0 0 3 0 0 0;0 2 0 0 5 0 0 6 0;
0 5 0 0 4 0 0 2 0;0 0 0 8 0 0 0 3 0;0 0 0 1 0 0 0 4 0];
tic;M=sudoku(M);toc;size(M,3)

인용 양식

Michael Kleder (2024). Fast Sudoku Solver (https://www.mathworks.com/matlabcentral/fileexchange/13324-fast-sudoku-solver), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R14SP3
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Sudoku에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0.0

Faster deductive logic engine now (apparently) finds everything that can be deduced without guessing.