Solves Sudoku using naked singles and recursive backtracking.
Y = sudoku_solverecursive ( X ) Y = sudoku_solverecursive ( X , verbose ) Y = sudoku_solverecursive ( X , verbose , level ) [Y,maxlevel] = sudoku_solverecursive ( ... )
a 9-by-9 matrix, with 0 for unknown entries
a boolean. Set to %t to display the state of the matrix. (default = %f)
the current level of recursive backtracking
the maximum level of the call tree in the nested recursive search used in the guess-based strategy
Using Recursive Backtracking. From an algorithm published in The Mathworks News and Notes, 2009.
There are several main improvements over the original algorithm. The matrix of candidates used in the logic process searching for naked singles is updated instead of being re-computed each time. When guessing is necessary, we do not take the first empty cell, but chose the cell with the lowest number of candidates. When we browse the candidates, we permute randomly the candidates so that the routine can be used to generate random grids.