function  sudoku(puz,integer)

switch puz
case 1
S  = [0,0,1,9,0,0,0,0,8;6,0,0,0,8,5,0,3,0;0,0,7,0,6,0,1,0,0;...
      0,3,4,0,9,0,0,0,0;0,0,0,5,0,4,0,0,0;0,0,0,0,1,0,4,2,0;...
      0,0,5,0,7,0,9,0,0;0,1,0,8,4,0,0,0,7;7,0,0,0,0,9,2,0,0];
case 2
S  = [8 3 0 0 0 0 7 0 0; 7 6 0 0 2 0 0 0 0; 2 0 0 4 0 0 0 0 0;...
      4 0 0 0 0 8 0 0 0; 1 0 8 0 0 0 3 0 7; 0 0 0 6 0 0 0 0 4;...
      0 0 0 0 0 5 0 0 3; 0 0 0 0 3 0 0 9 8; 0 0 9 0 0 0 0 1 6];
case 3
S  = [0 0 0 6 0 0 2 0 0; 8 0 4 0 3 0 0 0 0; 0 0 0 0 0 9 0 0 0;...
      4 0 5 0 0 0 0 0 7; 7 1 0 0 0 0 0 0 0; 0 0 3 0 5 0 0 0 8;...
      3 0 0 0 7 0 0 0 4; 0 0 0 0 0 1 9 0 0; 0 0 0 2 0 0 0 6 0];
case 4
S   = [8 0 0 0 0 0 0 0 0; 0 0 3 6 0 0 0 0 0; 0 7 0 0 9 0 2 0 0;...
       0 5 0 0 0 7 0 0 0; 0 0 0 0 4 5 7 0 0; 0 0 0 1 0 0 0 3 0;...
       0 0 1 0 0 0 0 6 8; 0 0 8 5 0 0 0 1 0; 0 9 0 0 0 0 4 0 0];
case 5
S    = [8 0 0 0 0 0 0 0 0; 0 0 3 6 0 0 0 0 0; 0 7 0 0 9 0 2 0 0;
        0 5 0 0 0 7 0 0 0; 0 0 0 0 4 5 7 0 0; 0 0 0 1 0 0 0 3 0;
        0 0 1 0 0 0 0 6 8; 0 0 8 5 0 0 0 1 0; 0 9 0 0 0 0 4 0 0];
case 6
S    = [0 0 0 0 0 0 0 0 0; 0 0 0 0 0 3 0 8 5; 0 0 1 0 2 0 0 0 0;
        0 0 0 5 0 7 0 0 0; 0 0 4 0 0 0 1 0 0; 0 9 0 0 0 0 0 0 0;
        5 0 0 0 0 0 0 7 3; 0 0 2 0 1 0 0 0 0; 0 0 0 0 4 0 0 0 9];
case 7
S    = [0 0 0 0 0 6 0 0 0; 
        0 5 9 0 0 0 0 0 8; 
        2 0 0 0 0 8 0 0 0; 
        0 4 5 0 0 0 0 0 0; 
        0 0 3 0 0 0 0 0 0; 
        0 0 6 0 0 3 0 5 4;
        0 0 0 3 2 5 0 0 6; 
        0 0 0 0 0 0 0 0 0; 
        0 0 0 0 0 0 0 0 0];
case 8
S    = [0 0 0 0 0 5 0 8 0; 
        0 0 0 6 0 1 0 4 3; 
        0 0 0 0 0 0 0 0 0; 
        0 1 0 5 0 0 0 0 0; 
        0 0 0 1 0 6 0 0 0; 
        3 0 0 0 0 0 0 0 5;
        5 3 0 0 0 0 0 6 1; 
        0 0 0 0 0 0 0 0 4; 
        0 0 0 0 0 0 0 0 0]; 
case 9
S = [0 0 0 1 0 0 6 7 0;
     0 0 0 0 0 6 0 0 4;
     0 0 5 4 0 0 1 0 0;
     0 8 3 0 6 0 0 0 2;
     5 0 0 0 0 0 0 0 8;
     1 0 0 0 3 0 7 6 0;
     0 0 1 0 0 3 4 0 0;
     2 0 0 5 0 0 0 0 0;
     0 7 6 0 0 2 0 0 0];
case 10
S = [0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 3 0 8 5;
     0 0 1 0 2 0 0 0 0;
     0 0 0 5 0 7 0 0 0;
     0 0 4 0 0 0 1 0 0;
     0 9 0 0 0 0 0 0 0;
     5 0 0 0 0 0 0 7 3;
     0 0 2 0 1 0 0 0 0;
     0 0 0 0 4 0 0 0 9];
end
p = 3;
if integer == 1
  A = binvar(p^2,p^2,p^2,'full');
else
  A = sdpvar(p^2,p^2,p^2,'full');
end

F = [sum(A,1) == 1, sum(A,2) == 1, sum(A,3) == 1];
F = [F, 0<=A];


for m = 1:p
    for n = 1:p
        for k = 1:p^2
            s = sum(sum(A((m-1)*p+(1:p),(n-1)*p+(1:p),k)));             
            F = [F, s == 1];
        end
    end
end

[i,j,k] = find(S);
F = [F, A(sub2ind([p^2 p^2 p^2],i,j,k)) == 1];
Objective = -sum(A);

F

if integer==1
  sol = solvesdp(F);
else 
  options = sdpsettings('verbose',2,'solver','linprog');
  options.linprog
  sol = solvesdp(F,[],options);
end


%


%A = round(double(A))

Z = 0;
for i = 1:p^2
      Z = Z  + i*double(A(:,:,i));
end
%round(Z)

Z

