Sudoku Problem Sudokutxt contains a 9 times 9 matrix solutio
Solution
% sudoku program
function x = sudoku(x)
% c is a cell array
 %s1 is the first cell , if any with one candidate
 %s2 is the first cell , with no candidates
[c,s1,s2] = candidates(x);
 while ~isempty(s1) && isemty(s2)
 x(s1) = c{s1};
 [c,s1,s2] = candidates(x);
 end
% it returns impossible puzzles
 if ~isempty(s2)
 return
 end
% It is for Recursive backtracking function
 if any(x(:) == 0)
 y=x;
 z = find(x(:) == 0,1);
 for r = [c{z}]
 x = y;
 x(z) = r;
 x = sudoku(x);
 if all(x(:) > 0)
 return
 end
 end
 end
 function [c,s1,s2] = candidates(x)
 c = cell(9,9);
 tri = @(k) 3*ceil(k/3-1) + (1:3);
 for j = 1:9
 for i = 1:9
 if x(i,j)==0
 z = 1:9;
 z(nonzeros(X(i,:))) = 0;
 z(nonzeros(X(:,j))) = 0;
 z(nonzeros(X(tri(i),tri(j)))) = 0;
 c{i,j} = nonzero(z)\';
 end
 end
 end
L = cellfun(@length,c);
 s1 = find(x==0 & L==1,1);
 s2 = find(x==0 & L==0,1);
 end
 end


