program tangle; (* Program to solve Rubiks Tangle1, V2.0, 1999-12-25 *) label loop1, loop2, loop3 ; var t: array [1..25,1..8] of byte; (* Description of one tangle piece: 34 t(x,1..8) tells the color of the rope-ends 1..8 of piece Nr x. 2 5 The original name of the pieces A..Y become here Nr 1..25 . 1R 6 Turn the piece such that R of Rubik is in low left corner, 87 start enumerating the colors clockwise with colorcode 1=red, 2=green, 3=blue, 4=yellow *) rot: array [1..8,1..4] of byte; (* Description of a rotation: rot(i,j) = position of rope-end Nr i, if it is turned j-1 quarters COUNTERclockwise *) fld: array [0..4,0..4] of byte; (* The solution field: fld(x,y) gives the Nr of the piece in place(x,y), origin is top left corner! *) tangstat: array [1..25] of byte; (* The rotation status of piece Nr x: j if turned j-1 quarters CLOCKwise *) color: array [0..4,0..4,5..8] of byte; (* color(x,y,z) is the color of the rope-end z of the piece in place (x,y) *) i,j,u,v,is,js,nb,flg4: integer; begin (* 1. fill rot. rot() helps just to save a little computing time *) for i:=1 to 8 do begin rot[i,1]:=i; u:=i-2; if (u<1) then u:=u+8; rot[i,2]:=u; u:=u-2; if (u<1) then u:=u+8; rot[i,3]:=u; u:=u-2; if (u<1) then u:=u+8; rot[i,4]:=u end; (* 2. fill tangle-data : the data was coded to tangle.col and deciphered by tangle.rex *) t[01,1]:=2;t[01,2]:=4;t[01,3]:=1;t[01,4]:=2;t[01,5]:=4;t[01,6]:=3;t[01,7]:=1;t[01,8]:=3; t[02,1]:=3;t[02,2]:=4;t[02,3]:=1;t[02,4]:=3;t[02,5]:=4;t[02,6]:=2;t[02,7]:=1;t[02,8]:=2; t[03,1]:=1;t[03,2]:=2;t[03,3]:=4;t[03,4]:=2;t[03,5]:=3;t[03,6]:=1;t[03,7]:=4;t[03,8]:=3; t[04,1]:=4;t[04,2]:=3;t[04,3]:=2;t[04,4]:=3;t[04,5]:=1;t[04,6]:=4;t[04,7]:=2;t[04,8]:=1; t[05,1]:=3;t[05,2]:=1;t[05,3]:=4;t[05,4]:=1;t[05,5]:=2;t[05,6]:=3;t[05,7]:=4;t[05,8]:=2; t[06,1]:=3;t[06,2]:=2;t[06,3]:=4;t[06,4]:=3;t[06,5]:=2;t[06,6]:=1;t[06,7]:=4;t[06,8]:=1; t[07,1]:=1;t[07,2]:=4;t[07,3]:=3;t[07,4]:=2;t[07,5]:=1;t[07,6]:=3;t[07,7]:=2;t[07,8]:=4; t[08,1]:=2;t[08,2]:=1;t[08,3]:=4;t[08,4]:=3;t[08,5]:=2;t[08,6]:=4;t[08,7]:=3;t[08,8]:=1; t[09,1]:=1;t[09,2]:=2;t[09,3]:=4;t[09,4]:=1;t[09,5]:=2;t[09,6]:=3;t[09,7]:=4;t[09,8]:=3; t[10,1]:=1;t[10,2]:=4;t[10,3]:=2;t[10,4]:=3;t[10,5]:=1;t[10,6]:=2;t[10,7]:=3;t[10,8]:=4; t[11,1]:=4;t[11,2]:=1;t[11,3]:=3;t[11,4]:=1;t[11,5]:=2;t[11,6]:=4;t[11,7]:=3;t[11,8]:=2; t[12,1]:=3;t[12,2]:=4;t[12,3]:=2;t[12,4]:=3;t[12,5]:=4;t[12,6]:=1;t[12,7]:=2;t[12,8]:=1; t[13,1]:=4;t[13,2]:=1;t[13,3]:=3;t[13,4]:=2;t[13,5]:=4;t[13,6]:=2;t[13,7]:=1;t[13,8]:=3; t[14,1]:=2;t[14,2]:=1;t[14,3]:=3;t[14,4]:=1;t[14,5]:=4;t[14,6]:=2;t[14,7]:=3;t[14,8]:=4; t[15,1]:=2;t[15,2]:=3;t[15,3]:=4;t[15,4]:=1;t[15,5]:=2;t[15,6]:=4;t[15,7]:=1;t[15,8]:=3; t[16,1]:=3;t[16,2]:=2;t[16,3]:=1;t[16,4]:=4;t[16,5]:=3;t[16,6]:=4;t[16,7]:=2;t[16,8]:=1; t[17,1]:=3;t[17,2]:=1;t[17,3]:=2;t[17,4]:=3;t[17,5]:=1;t[17,6]:=4;t[17,7]:=2;t[17,8]:=4; t[18,1]:=1;t[18,2]:=3;t[18,3]:=4;t[18,4]:=2;t[18,5]:=1;t[18,6]:=4;t[18,7]:=2;t[18,8]:=3; t[19,1]:=2;t[19,2]:=3;t[19,3]:=1;t[19,4]:=4;t[19,5]:=2;t[19,6]:=1;t[19,7]:=4;t[19,8]:=3; t[20,1]:=2;t[20,2]:=4;t[20,3]:=1;t[20,4]:=3;t[20,5]:=2;t[20,6]:=1;t[20,7]:=3;t[20,8]:=4; t[21,1]:=1;t[21,2]:=2;t[21,3]:=3;t[21,4]:=1;t[21,5]:=2;t[21,6]:=4;t[21,7]:=3;t[21,8]:=4; t[22,1]:=4;t[22,2]:=3;t[22,3]:=2;t[22,4]:=1;t[22,5]:=4;t[22,6]:=2;t[22,7]:=1;t[22,8]:=3; t[23,1]:=4;t[23,2]:=3;t[23,3]:=1;t[23,4]:=4;t[23,5]:=3;t[23,6]:=2;t[23,7]:=1;t[23,8]:=2; t[24,1]:=3;t[24,2]:=2;t[24,3]:=4;t[24,4]:=1;t[24,5]:=3;t[24,6]:=4;t[24,7]:=1;t[24,8]:=2; t[25,1]:=3;t[25,2]:=2;t[25,3]:=1;t[25,4]:=4;t[25,5]:=3;t[25,6]:=1;t[25,7]:=4;t[25,8]:=2; for i:=1 to 25 do tangstat[i]:=0; for i:=0 to 4 do for j:=0 to 4 do fld[i,j]:=0; (* main loops *) i:=0; j:=0; fld[0,0]:=1; tangstat[1]:=0; flg4:=0; (* flg4: piece Nr 4 is not yet set *) loop1: u:=fld[i,j]; v:=tangstat[u]; loop2: (* u>2: piece Nr u=1 can not be rotated! *) if ((u>1) and (v<4)) then inc(v) else begin tangstat[u]:=0; v:=1; if (u=4) then flg4:=0; (* Piece Nr 4 has just been removed *) loop3: inc(u); if (u=26) then begin dec(j); if (j=-1) then begin j:=4; dec(i) end; if (i=-1) then begin writeln('End of Program.'); halt end; goto loop1 end; if (tangstat[u]>0) then goto loop3; (* Piece Nr u=19 can only be set if Piece Nr 4 is already used *) if ((u=19) and (flg4=0)) then goto loop3 end; if (i>0) then begin if (t[u,rot[1,v]]<>color[i-1,j,6]) then goto loop2; if (t[u,rot[2,v]]<>color[i-1,j,5]) then goto loop2 end; if (j>0) then begin if (t[u,rot[3,v]]<>color[i,j-1,8]) then goto loop2; if (t[u,rot[4,v]]<>color[i,j-1,7]) then goto loop2 end; tangstat[u]:=v; fld[i,j]:=u; if (u=4) then flg4:=1; color[i,j,5]:=t[u,rot[5,v]]; color[i,j,6]:=t[u,rot[6,v]]; color[i,j,7]:=t[u,rot[7,v]]; color[i,j,8]:=t[u,rot[8,v]]; (* a piece is successfully placed, get next place in the 5x5 field *) inc(j); if (j=5) then begin j:=0; inc(i) end; (* if we are at the end, we have a solution! *) if (i=5) then begin write('Solution: '); for js:=0 to 4 do for is:=0 to 4 do write(chr(fld[is,js]+64)); writeln end; (* clear the current field before trying to put a piece in *) u:=0; v:=1; fld[i,j]:=0; goto loop3 end.