program cube4_2;

//checks all combinations of 4 cubes to set in a line
//there's a game with 4 cubes and you have to set
//1.1.1.1/2.2.2.2/3.3.3.3/4.4.4.4/ for each surface of 4*3 cubes!
//shows use of n variables of a 1 dim array, loc's = 187

 
type  
   TCube = array[1..6] of byte;
var
   cube1: TCube;
   cube2: TCube;
   cube3: TCube;
   cube4: TCube;
   cube1a: TCube;
   cube1b: TCube;
   cube2a: TCube;
   cube2b: TCube;
   cube3a: TCube;
   cube3b: TCube;
   cube4a: TCube;
   cube4b: TCube;

//function getCube: boolean; forward; 
function getCube(const cube: TCube; posit, idx: byte): byte;
begin
  if idx = 1 then
  case posit of 
    1: result:= cube[1]
    2: result:= cube[2]
    3: result:= cube[3]
    4: result:= cube[4]
    end;
  if idx = 2 then
    case posit of 
    1: result:= cube[2]
    2: result:= cube[3]
    3: result:= cube[4]
    4: result:= cube[1]
    end;
  if idx = 3 then
    case posit of 
    1: result:= cube[3]
    2: result:= cube[4]
    3: result:= cube[1]
    4: result:= cube[2]
    end;  
  if idx = 4 then
    case posit of 
    1: result:= cube[4]
    2: result:= cube[1]
    3: result:= cube[2]
    4: result:= cube[3]
    end;  
end;     
  
  
function checkCube(const cube1,cube2,cube3,cube4: TCube; i,k,l,m: byte):boolean;
begin
//cube test of sum 4,12,10,11 or 4,8,10,12, main test is 4,8,12,16
result:= false;
if (getCube(cube1,i,1)+getCube(cube2,k,1)+getCube(cube3,l,1)+getCube(Cube4,m,1) = 10) and
   (getCube(cube1,i,2)+getCube(cube2,k,2)+getCube(cube3,l,2)+getCube(Cube4,m,2) = 10) and
   (getCube(cube1,i,3)+getCube(cube2,k,3)+getCube(cube3,l,3)+getCube(Cube4,m,3) = 10) and  
   (getCube(cube1,i,4)+getCube(cube2,k,4)+getCube(cube3,l,4)+getCube(Cube4,m,4) = 10)     
  then begin
     writeln(inttostr(getCube(cube1,1,i))+inttostr(getcube(cube2,1,k))+
             inttostr(getCube(cube3,1,l))+inttostr(getCube(cube4,1,m))) 
     writeln(inttostr(getCube(cube1,2,i))+inttostr(getcube(cube2,2,k))+
             inttostr(getCube(cube3,2,l))+inttostr(getCube(cube4,2,m))) 
     writeln(inttostr(getCube(cube1,3,i))+inttostr(getcube(cube2,3,k))+
             inttostr(getCube(cube3,3,l))+inttostr(getCube(cube4,3,m))) 
     writeln(inttostr(getCube(cube1,4,i))+inttostr(getcube(cube2,4,k))+
             inttostr(getCube(cube3,4,l))+inttostr(getCube(cube4,4,m)))          
     result:= true;
  end 
end;         
    

function cube_tester(id,kd,ld,md: byte): boolean;
var i,k,l,m, count: byte;
  cubea, cubeb, cubec, cubed: TCube;
 //  i       k       l      m
//cube1   ,cube2  ,cube3  ,cube4
//cube1a  ,cube2a ,cube3a ,cube4a
//cube1b  ,cube2b ,cube3b ,cube4b
begin
 count:= 0;
 for i:= 1 to 3 do 
    for k:= 1 to 3 do 
      for l:= 1 to 3 do 
         for m:= 1 to 3 do begin
         //writeln(inttostr(i)+inttostr(k)+inttostr(l)+inttostr(m))
           if i=1 then cubea:= cube1
           if i=2 then cubea:= cube1a
           if i=3 then cubea:= cube1b
           if k=1 then cubeb:= cube2
           if k=2 then cubeb:= cube2a
           if k=3 then cubeb:= cube2b
           if l=1 then cubec:= cube3
           if l=2 then cubec:= cube3a
           if l=3 then cubec:= cube3b
           if m=1 then cubed:= cube4
           if m=2 then cubed:= cube4a
           if m=3 then cubed:= cube4b
           if checkCube(cubea,cubeb,cubec,cubed, id,kd,ld,md) then
             result:= true;
           count:= count +1 ;
         end;
end;   
 

procedure set_CubeData;
begin 
// 4 cube data from wood cube - forward then left and right
cube1[1]:= 1; cube1[2]:= 2; cube1[3]:= 2; cube1[4]:= 3;
//cube1[5]:= 3; cube1[6]:= 4;
cube1a[1]:= 1; cube1a[2]:= 4; cube1a[3]:= 2; cube1a[4]:= 3;
cube1b[1]:= 3; cube1b[2]:= 2; cube1b[3]:= 4; cube1b[4]:= 3;

cube2[1]:= 1; cube2[2]:= 1; cube2[3]:= 3; cube2[4]:= 4;
//cube2[5]:= 2; cube2[6]:= 3;
cube2a[1]:= 1; cube2a[2]:= 3; cube2a[3]:= 3; cube2a[4]:= 2;
cube2b[1]:= 2; cube2b[2]:= 1; cube2b[3]:= 3; cube2b[4]:= 4;

cube3[1]:= 1; cube3[2]:= 2; cube3[3]:= 1; cube3[4]:= 1;
//cube3[5]:= 4; cube3[6]:= 3;
cube3a[1]:= 1; cube3a[2]:= 3; cube3a[3]:= 1; cube3a[4]:= 4;
cube3b[1]:= 4; cube3b[2]:= 2; cube3b[3]:= 3; cube3b[4]:= 1;

cube4[1]:= 1; cube4[2]:= 3; cube4[3]:= 4; cube4[4]:= 4;
//cube4[5]:= 2; cube4[6]:= 2;
cube4a[1]:= 1; cube4a[2]:= 2; cube4a[3]:= 4; cube4a[4]:= 2;
cube4b[1]:= 2; cube4b[2]:= 3; cube4b[3]:= 2; cube4b[4]:= 4;
writeln('((((((((((((((((((cube set))))))))))))))))))))');
end; 
  

procedure cube_permutation;
// testparams = 4,9,11,10 normaltest=4,8,12,16 =sum4*1+4*2+4*3+4*4 
var
 i,k,l,m: byte;
 count, countb: integer;
begin
 count:= 0;
 countb:= 0;
 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
            //range checking
            //if (i <4) and (k <4) and (l<4) and (m <4) and
           inc(countb)
           if cube_tester(i,k,l,m) then begin
           //if checkCube(cube1,cube2,cube3,cube4, i,k,l,m) or
             inc(count);
             writeln('------');
           end;  
         end
         writeln(inttostr(countb * 81)+' runs');
         writeln(inttostr(count)+' are success')
         writeln('------------------')
         writeln('check '+ inttostr((getCube(cube1,1,2)+getCube(cube2a,1,2)
                  +getCube(cube3b,1,3)+getCube(Cube4b,1,2))))
        {if (getCube(cube1b,1,1)+getCube(cube2,1,1)+getCube(cube3a,1,1)+getCube(Cube4a,1,1)=6) and
        (getCube(cube1b,1,2)+getCube(cube2,1,2)+getCube(cube3a,1,2)+getCube(Cube4a,1,2)=8) then
         showmessage('well done')}
end;
  

//main cube calculate
begin
  //4 cube tester
  set_CubeData;
  cube_permutation;
end.

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

