function ShowSudoku()
% Test Script for Sudoku Problem
close all
C = PuzzleLibrary();
% Pick a random Sudoku matrix from the library...
S = C{ceil(length(C)*rand())};
% Show the solution and an associated Easy, Medium, and Hard puzzle...
ShowPuzzle(S,'Solution')
[T,k] = MakePuzzle(S,'Easy');
ShowPuzzle(T,sprintf('Easy Required Trials = %1d',k))
[T,k] = MakePuzzle(S,'Medium');
ShowPuzzle(T,sprintf('Medium Required Trials = %1d',k))
[T,k] = MakePuzzle(S,'Hard');
ShowPuzzle(T,sprintf('Hard Required Trials = %1d',k))

function ShowPuzzle(S,message)
% S is a punched out Suduko matrix.
% S is displayed in a new figure window.

% Magenta square with a black grid...
figure
size = 600;
fill([1 10 10 1],[1 1 10 10],'m')
set(gcf,'position',[400 200 size size])
axis equal off ij
hold on
for x = 1:3:10
plot([x x],[1 10],'k','linewidth',5)
plot([1 10],[x x],'k','linewidth',5)
end
for x = 1:10
plot([x x],[1 10],'k','linewidth',2)
plot([1 10],[x x],'k','linewidth',2)
end
% Visit each tile perhaps write a value...
for i=1:9
for j=1:9
if S(i,j)>0
% S(i,j) is not punched out.
text(j+.4,i+.5,sprintf('%1d',S(i,j)),'fontsize',18)
end
end
end
hold off
title(message,'Fontsize',18)

function C = PuzzleLibrary()
% Returns a cell array of Sudoku matrices.
C{1} = [ 9 4 5 8 2 1 6 7 3;...
8 7 6 5 3 9 1 2 4;...
3 2 1 4 7 6 5 8 9;...
2 9 3 1 6 4 8 5 7;...
4 5 8 7 9 2 3 6 1;...
6 1 7 3 8 5 4 9 2;...
7 6 4 9 5 3 2 1 8;...
5 3 9 2 1 8 7 4 6;...
1 8 2 6 4 7 9 3 5];
C{2} = [ 7 5 4 2 9 6 3 1 8;...
9 6 3 1 8 5 2 4 7;...
2 8 1 7 3 4 5 6 9;...
8 4 6 5 1 7 9 3 2;...
5 3 9 8 6 2 1 7 4;...
1 7 2 3 4 9 8 5 6;...
6 1 8 9 7 3 4 2 5;...
4 9 5 6 2 1 7 8 3;...
3 2 7 4 5 8 6 9 1];
C{3} = [ 5 3 8 7 9 4 1 2 6;...
7 2 1 3 6 8 9 4 5;...
6 4 9 5 2 1 8 7 3;...
4 7 6 2 5 9 3 8 1;...
2 8 5 1 3 6 4 9 7;...
1 9 3 8 4 7 6 5 2;...
9 6 2 4 7 3 5 1 8;...
3 1 7 9 8 5 2 6 4;...
8 5 4 6 1 2 7 3 9];