function TestSudoku()
% Checks out Sudoku...
clc
% A correct example
A = [ 3 5 1 2 8 9 7 4 6;...
      2 4 9 6 7 1 5 3 8;...
      8 7 6 3 4 5 2 1 9;...
      4 6 7 5 9 8 3 2 1;...
      5 9 3 1 2 4 8 6 7;...
      1 2 8 7 6 3 4 9 5;...
      9 3 5 4 1 7 6 8 2;...
      6 8 4 9 5 2 1 7 3;...
      7 1 2 8 3 6 9 5 4];
 z1 = Sudoku(A)
 A2 = A(:,[1 2 4 3 5 6 7 8 9]); z2 = Sudoku(A2) % Some blocks wrong
 A3 = A;  A3(1,1)=1; A3(1,3)=3; z3 = Sudoku(A3) % Some columns wrong
 A4 = A;  A4(1,1)=8; A4(3,1)=3; z4 = Sudoku(A4) % Some rows wrong
 

  function z = SudokuCVL(A)
% A is a 9-by-9 matrix
% Returns 0 or 1 depending on whether A is a valid Sudoku solution or not

% Each of the 27 columns in this matrix should be a permutation of (1:9)':
B = [A A' reshape(A(:,1:3)',9,3) reshape(A(:,4:6)',9,3) reshape(A(:,7:9)',9,3)];
z = norm((1:9)'*ones(1,27) - sort(B)) == 0;