program Sudoku_Statistics_2;

// ...shows a 4*4 sudoku like calculation of the possibilities
//solution is sqr (4!4!4!4!)  = 756 possibilities with diagonals = 48
//shows the use of 2 dim arrays, loc's=105

type  
    TPerm = array[1..4] of byte;
    //TCube = array[1..6] of byte;


procedure sudok_permutation;
//solution is sqr 4!4!4!4!  = 756 with diagonal = 48
var  
   perm: TPerm;
   resu: array[1..24] of TPerm;
   i,k,l,m: byte;
   count, suma: integer;
   
begin
perm[1]:= 1;
perm[2]:= 2;
perm[3]:= 4;
perm[4]:= 8;
i:=1; k:=1;
l:=1; m:=1;
count:= 0;
suma:= 0;
writeln('((((((((((((((start of full sudokus)))))))))))))))');
 for i:= 1 to 4 do 
   for k:= 1 to 4 do 
     for l:= 1 to 4 do 
       for m:= 1 to 4 do begin
         //writeln(inttostr(perm[i])+inttostr(perm[k])+inttostr(perm[l])+
         //inttostr(perm[m]))
         //sure to make each number single
         suma:= perm[i]+perm[k]+perm[l]+perm[m]
         if suma = 15 then begin
         //writeln(inttoStr(suma))
           inc(count);
           //2 dim arrays
           resu[count][1]:= perm[i]
           resu[count][2]:= perm[k]
           resu[count][3]:= perm[l]
           resu[count][4]:= perm[m]
           writeln(inttostr(resu[count][1])+inttostr(resu[count][2])+
                   inttostr(resu[count][3])+inttostr(resu[count][4]))        
         end;  
            //write(inttostr(perm[m]));
          //write('-test-')
       end
       writeln('----------end of single lines-----------')
       writeln('');
     
   count:= 0;
   suma:= 0;    
   for i:= 1 to 24 do 
     for k:= 1 to 24 do 
       for l:= 1 to 24 do 
         for m:= 1 to 24 do begin
           //writeln(inttostr(perm[i])+inttostr(perm[k])+inttostr(perm[l])+
             //inttostr(perm[m]))
            suma:=0;
            if (resu[i][1]+resu[k][1]+resu[l][1]+resu[m][1] = 15) and
               (resu[i][2]+resu[k][2]+resu[l][2]+resu[m][2] = 15) and
               (resu[i][3]+resu[k][3]+resu[l][3]+resu[m][3] = 15) and
               (resu[i][4]+resu[k][4]+resu[l][4]+resu[m][4] = 15) and
               //check also diagonals  
               (resu[i][1]+resu[k][2]+resu[l][3]+resu[m][4] = 15) and
               (resu[m][1]+resu[l][2]+resu[k][3]+resu[i][4] = 15) then begin
              //writeln(inttoStr(suma))
                 inc(count);
                 write(inttostr(count))
                 //change the symbols here
                 writeln(inttostr(resu[i][1])+inttostr(resu[i][2])+
                         inttostr(resu[i][3])+inttostr(resu[i][4]))        
                 writeln(inttostr(resu[k][1])+inttostr(resu[k][2])+
                         inttostr(resu[k][3])+inttostr(resu[k][4]))        
                 writeln(inttostr(resu[l][1])+inttostr(resu[l][2])+
                         inttostr(resu[l][3])+inttostr(resu[l][4]))        
                 writeln(inttostr(resu[m][1])+inttostr(resu[m][2])+
                         inttostr(resu[m][3])+inttostr(resu[m][4]))        

                 writeln('------((((((((()))))))))------') 
            end; 
         end;
    writeln('4*4 sudokus: '+inttostr(count))       
end;


// main sudo
begin
//sudo tester  
  sudok_permutation;
end.

just maXbox from
         ____    ___   _      ____    _   _   _
        |  _ \  |  _| | |    |  _ \  | | | | | |
        | | . | | |_  | |    | |_| | | |_| | | |
        | | | | |  _| | |    |  __/  |  _  | | |          
        | |_. | | |_  | |__  | |     | | | | | |                      
        |____/  |___| |____| |_|     |_| |_| |_| 
                                     

