Code covered by the BSD License  

Highlights from
Fast Sudoku Solver

image thumbnail
from Fast Sudoku Solver by Yue Wu
An algorithm to mimic human solving procedure for Sudoku puzzles

sudoku_lowmode(xcell)
function output = sudoku_lowmode(xcell)
% Function: sudoku_lowmode
%           used for getting all number that just appears once in the cell
%           
% Input: xcell = 1x9 or 9x1 or 3x3 cell
% Output: output = 9x1 cell, each cell will contain the numbers that just
%         appears once in the corresponding cell in xcell 
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is a sub-function of the sub-function sudoku_stage1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% All copyrights reserved
% By Yue Wu
% 10/05/2009
% ECE Dept, Tufts Univ.
% MA, Medford 02155
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for i = 1:9
    clear tmpcell
    tmpcell = xcell{i}; % each time, extract one cell in xcell
    % calculate the frequency for each possible number
    for j = 1:9
        flist(j) = length(find(tmpcell == j));
    end
    % find its lowest frequency
    minj = min(flist);
    if minj == 1 % if lowest frequency = 1, find all the numbers with this frequency
        output{i} = find(flist == minj);
    else % otherwise, return to empty list
        output{i} = [];
    end
end

Contact us at files@mathworks.com