## ## ## rubik4.mpl ## simulates the moves of the 4x4 Rubik's cube ## ## David Joyner, 1996 ########################################################### A0:=matrix([ [1,1,1,1,6,6,6,6,3,3,3,3], [1,1,1,1,6,6,6,6,3,3,3,3], [1,1,1,1,6,6,6,6,3,3,3,3], [1,1,1,1,6,6,6,6,3,3,3,3], [2,2,2,2,5,5,5,5,4,4,4,4], [2,2,2,2,5,5,5,5,4,4,4,4], [2,2,2,2,5,5,5,5,4,4,4,4], [2,2,2,2,5,5,5,5,4,4,4,4]]); color1 := red; color2 := blue; color3 := coral; color4 := plum; color5 := green; color6 := yellow; rubik_squares := proc () local i; for i from 1 to 5 do F1.i:=[5,-3+2*(i-1),5]; F2.i:=[5,-3+2*(i-1),3]; F3.i:=[5,-3+2*(i-1),1]; F4.i:=[5,-3+2*(i-1),-1]; F5.i:=[5,-3+2*(i-1),-3]; R1.i:=[5-2*(i-1),5,5]; R2.i:=[5-2*(i-1),5,3]; R3.i:=[5-2*(i-1),5,1]; R4.i:=[5-2*(i-1),5,-1]; R5.i:=[5-2*(i-1),5,-3]; B1.i:=[-3,5-2*(i-1),5]; B2.i:=[-3,5-2*(i-1),3]; B3.i:=[-3,5-2*(i-1),1]; B4.i:=[-3,5-2*(i-1),-1]; B5.i:=[-3,5-2*(i-1),-3]; L1.i:=[-3+2*(i-1),-3,5]; L2.i:=[-3+2*(i-1),-3,3]; L3.i:=[-3+2*(i-1),-3,1]; L4.i:=[-3+2*(i-1),-3,-1]; L5.i:=[-3+2*(i-1),-3,-3]; U1.i:=[-3,-3+2*(i-1),5]; U2.i:=[-1,-3+2*(i-1),5]; U3.i:=[1,-3+2*(i-1),5]; U4.i:=[3,-3+2*(i-1),5]; U5.i:=[5,-3+2*(i-1),5]; D1.i:=[-3,5-2*(i-1),-3]; D2.i:=[-1,5-2*(i-1),-3]; D3.i:=[1,5-2*(i-1),-3]; D4.i:=[3,5-2*(i-1),-3]; D5.i:=[5,5-2*(i-1),-3]; od; end; cube_draw := proc (A::array) local i, j, face_F11,face_F12,face_F13,face_F14, face_F21,face_F22,face_F23,face_F24, face_F31,face_F32,face_F33,face_F34, face_F41,face_F42,face_F43,face_F44, face_B11,face_B12,face_B13,face_B14, face_B21,face_B22,face_B23,face_B24, face_B31,face_B32,face_B33,face_B34, face_B41,face_B42,face_B43,face_B44, face_U11,face_U12,face_U13,face_U14, face_U21,face_U22,face_U23,face_U24, face_U31,face_U32,face_U33,face_U34, face_U41,face_U42,face_U43,face_U44, face_R11,face_R12,face_R13,face_R14, face_R21,face_R22,face_R23,face_R24, face_R31,face_R32,face_R33,face_R34, face_R41,face_R42,face_R43,face_R44, face_L11,face_L12,face_L13,face_L14, face_L21,face_L22,face_L23,face_L24, face_L31,face_L32,face_L33,face_L34, face_L41,face_L42,face_L43,face_L44, face_D11,face_D12,face_D13,face_D14, face_D21,face_D22,face_D23,face_D24, face_D31,face_D32,face_D33,face_D34, face_D41,face_D42,face_D43,face_D44,L; rubik_squares(); face_F11:=polygonplot3d([F11,F12,F22,F21],style=patch, color=color.(A[1,1])); face_F12:=polygonplot3d([F12,F13,F23,F22],style=patch, color=color.(A[1,2])); face_F13:=polygonplot3d([F13,F14,F24,F23],style=patch, color=color.(A[1,3])); face_F14:=polygonplot3d([F14,F15,F25,F24],style=patch, color=color.(A[1,4])); face_F21:=polygonplot3d([F21,F22,F32,F31],style=patch, color=color.(A[2,1])); face_F22:=polygonplot3d([F22,F23,F33,F32],style=patch, color=color.(A[2,2])); face_F23:=polygonplot3d([F23,F24,F34,F33],style=patch, color=color.(A[2,3])); face_F24:=polygonplot3d([F24,F25,F35,F34],style=patch, color=color.(A[2,4])); face_F31:=polygonplot3d([F31,F32,F42,F41],style=patch, color=color.(A[3,1])); face_F32:=polygonplot3d([F32,F33,F43,F42],style=patch, color=color.(A[3,2])); face_F33:=polygonplot3d([F33,F34,F44,F43],style=patch, color=color.(A[3,3])); face_F34:=polygonplot3d([F34,F35,F45,F44],style=patch, color=color.(A[3,4])); face_F41:=polygonplot3d([F41,F42,F52,F51],style=patch, color=color.(A[4,1])); face_F42:=polygonplot3d([F42,F43,F53,F52],style=patch, color=color.(A[4,2])); face_F43:=polygonplot3d([F43,F44,F54,F53],style=patch, color=color.(A[4,3])); face_F44:=polygonplot3d([F44,F45,F55,F54],style=patch, color=color.(A[4,4])); face_B11:=polygonplot3d([B11,B12,B22,B21],style=patch, color=color.(A[1,9])); face_B12:=polygonplot3d([B12,B13,B23,B22],style=patch, color=color.(A[1,10])); face_B13:=polygonplot3d([B13,B14,B24,B23],style=patch, color=color.(A[1,11])); face_B14:=polygonplot3d([B14,B15,B25,B24],style=patch, color=color.(A[1,12])); face_B21:=polygonplot3d([B21,B22,B32,B31],style=patch, color=color.(A[2,9])); face_B22:=polygonplot3d([B22,B23,B33,B32],style=patch, color=color.(A[2,10])); face_B23:=polygonplot3d([B23,B24,B34,B33],style=patch, color=color.(A[2,11])); face_B24:=polygonplot3d([B24,B25,B35,B34],style=patch, color=color.(A[2,12])); face_B31:=polygonplot3d([B31,B32,B42,B41],style=patch, color=color.(A[3,9])); face_B32:=polygonplot3d([B32,B33,B43,B42],style=patch, color=color.(A[3,10])); face_B33:=polygonplot3d([B33,B34,B44,B43],style=patch, color=color.(A[3,11])); face_B34:=polygonplot3d([B34,B35,B45,B44],style=patch, color=color.(A[3,12])); face_B41:=polygonplot3d([B41,B42,B52,B51],style=patch, color=color.(A[4,9])); face_B42:=polygonplot3d([B42,B43,B53,B52],style=patch, color=color.(A[4,10])); face_B43:=polygonplot3d([B43,B44,B54,B53],style=patch, color=color.(A[4,11])); face_B44:=polygonplot3d([B44,B45,B55,B54],style=patch, color=color.(A[4,12])); face_U11:=polygonplot3d([U11,U12,U22,U21],style=patch, color=color.(A[5,1])); face_U12:=polygonplot3d([U12,U13,U23,U22],style=patch, color=color.(A[5,2])); face_U13:=polygonplot3d([U13,U14,U24,U23],style=patch, color=color.(A[5,3])); face_U14:=polygonplot3d([U14,U15,U25,U24],style=patch, color=color.(A[5,4])); face_U21:=polygonplot3d([U21,U22,U32,U31],style=patch, color=color.(A[6,1])); face_U22:=polygonplot3d([U22,U23,U33,U32],style=patch, color=color.(A[6,2])); face_U23:=polygonplot3d([U23,U24,U34,U33],style=patch, color=color.(A[6,3])); face_U24:=polygonplot3d([U24,U25,U35,U34],style=patch, color=color.(A[6,4])); face_U31:=polygonplot3d([U31,U32,U42,U41],style=patch, color=color.(A[7,1])); face_U32:=polygonplot3d([U32,U33,U43,U42],style=patch, color=color.(A[7,2])); face_U33:=polygonplot3d([U33,U34,U44,U43],style=patch, color=color.(A[7,3])); face_U34:=polygonplot3d([U34,U35,U45,U44],style=patch, color=color.(A[7,4])); face_U41:=polygonplot3d([U41,U42,U52,U51],style=patch, color=color.(A[8,1])); face_U42:=polygonplot3d([U42,U43,U53,U52],style=patch, color=color.(A[8,2])); face_U43:=polygonplot3d([U43,U44,U54,U53],style=patch, color=color.(A[8,3])); face_U44:=polygonplot3d([U44,U45,U55,U54],style=patch, color=color.(A[8,4])); face_R11:=polygonplot3d([R11,R12,R22,R21],style=patch, color=color.(A[1,5])); face_R12:=polygonplot3d([R12,R13,R23,R22],style=patch, color=color.(A[1,6])); face_R13:=polygonplot3d([R13,R14,R24,R23],style=patch, color=color.(A[1,7])); face_R14:=polygonplot3d([R14,R15,R25,R24],style=patch, color=color.(A[1,8])); face_R21:=polygonplot3d([R21,R22,R32,R31],style=patch, color=color.(A[2,5])); face_R22:=polygonplot3d([R22,R23,R33,R32],style=patch, color=color.(A[2,6])); face_R23:=polygonplot3d([R23,R24,R34,R33],style=patch, color=color.(A[2,7])); face_R24:=polygonplot3d([R24,R25,R35,R34],style=patch, color=color.(A[2,8])); face_R31:=polygonplot3d([R31,R32,R42,R41],style=patch, color=color.(A[3,5])); face_R32:=polygonplot3d([R32,R33,R43,R42],style=patch, color=color.(A[3,6])); face_R33:=polygonplot3d([R33,R34,R44,R43],style=patch, color=color.(A[3,7])); face_R34:=polygonplot3d([R34,R35,R45,R44],style=patch, color=color.(A[3,8])); face_R41:=polygonplot3d([R41,R42,R52,R51],style=patch, color=color.(A[4,5])); face_R42:=polygonplot3d([R42,R43,R53,R52],style=patch, color=color.(A[4,6])); face_R43:=polygonplot3d([R43,R44,R54,R53],style=patch, color=color.(A[4,7])); face_R44:=polygonplot3d([R44,R45,R55,R54],style=patch, color=color.(A[4,8])); face_L11:=polygonplot3d([L11,L12,L22,L21],style=patch, color=color.(A[5,5])); face_L12:=polygonplot3d([L12,L13,L23,L22],style=patch, color=color.(A[5,6])); face_L13:=polygonplot3d([L13,L14,L24,L23],style=patch, color=color.(A[5,7])); face_L14:=polygonplot3d([L14,L15,L25,L24],style=patch, color=color.(A[5,8])); face_L21:=polygonplot3d([L21,L22,L32,L31],style=patch, color=color.(A[6,5])); face_L22:=polygonplot3d([L22,L23,L33,L32],style=patch, color=color.(A[6,6])); face_L23:=polygonplot3d([L23,L24,L34,L33],style=patch, color=color.(A[6,7])); face_L24:=polygonplot3d([L24,L25,L35,L34],style=patch, color=color.(A[6,8])); face_L31:=polygonplot3d([L31,L32,L42,L41],style=patch, color=color.(A[7,5])); face_L32:=polygonplot3d([L32,L33,L43,L42],style=patch, color=color.(A[7,6])); face_L33:=polygonplot3d([L33,L34,L44,L43],style=patch, color=color.(A[7,7])); face_L34:=polygonplot3d([L34,L35,L45,L44],style=patch, color=color.(A[7,8])); face_L41:=polygonplot3d([L41,L42,L52,L51],style=patch, color=color.(A[8,5])); face_L42:=polygonplot3d([L42,L43,L53,L52],style=patch, color=color.(A[8,6])); face_L43:=polygonplot3d([L43,L44,L54,L53],style=patch, color=color.(A[8,7])); face_L44:=polygonplot3d([L44,L45,L55,L54],style=patch, color=color.(A[8,8])); face_D11:=polygonplot3d([D11,D12,D22,D21],style=patch, color=color.(A[5,9])); face_D12:=polygonplot3d([D12,D13,D23,D22],style=patch, color=color.(A[5,10])); face_D13:=polygonplot3d([D13,D14,D24,D23],style=patch, color=color.(A[5,11])); face_D14:=polygonplot3d([D14,D15,D25,D24],style=patch, color=color.(A[5,12])); face_D21:=polygonplot3d([D21,D22,D32,D31],style=patch, color=color.(A[6,9])); face_D22:=polygonplot3d([D22,D23,D33,D32],style=patch, color=color.(A[6,10])); face_D23:=polygonplot3d([D23,D24,D34,D33],style=patch, color=color.(A[6,11])); face_D24:=polygonplot3d([D24,D25,D35,D34],style=patch, color=color.(A[6,12])); face_D31:=polygonplot3d([D31,D32,D42,D41],style=patch, color=color.(A[7,9])); face_D32:=polygonplot3d([D32,D33,D43,D42],style=patch, color=color.(A[7,10])); face_D33:=polygonplot3d([D33,D34,D44,D43],style=patch, color=color.(A[7,11])); face_D34:=polygonplot3d([D34,D35,D45,D44],style=patch, color=color.(A[7,12])); face_D41:=polygonplot3d([D41,D42,D52,D51],style=patch, color=color.(A[8,9])); face_D42:=polygonplot3d([D42,D43,D53,D52],style=patch, color=color.(A[8,10])); face_D43:=polygonplot3d([D43,D44,D54,D53],style=patch, color=color.(A[8,11])); face_D44:=polygonplot3d([D44,D45,D55,D54],style=patch, color=color.(A[8,12])); L:= [ face_F11,face_F12,face_F13,face_F14, face_F21,face_F22,face_F23,face_F24, face_F31,face_F32,face_F33,face_F34, face_F41,face_F42,face_F43,face_F44, face_B11,face_B12,face_B13,face_B14, face_B21,face_B22,face_B23,face_B24, face_B31,face_B32,face_B33,face_B34, face_B41,face_B42,face_B43,face_B44, face_U11,face_U12,face_U13,face_U14, face_U21,face_U22,face_U23,face_U24, face_U31,face_U32,face_U33,face_U34, face_U41,face_U42,face_U43,face_U44, face_R11,face_R12,face_R13,face_R14, face_R21,face_R22,face_R23,face_R24, face_R31,face_R32,face_R33,face_R34, face_R41,face_R42,face_R43,face_R44, face_L11,face_L12,face_L13,face_L14, face_L21,face_L22,face_L23,face_L24, face_L31,face_L32,face_L33,face_L34, face_L41,face_L42,face_L43,face_L44, face_D11,face_D12,face_D13,face_D41, face_D21,face_D22,face_D23,face_D42, face_D31,face_D32,face_D33,face_D43, face_D14,face_D24,face_D34,face_D44]; RETURN(L) end; move_r1 := proc (A) local j, k, AA,indices; AA := matrix(8,12); indices:={[1,4],[1,5],[1,6],[1,7],[1,8],[1,9], [2,5],[2,4],[2,6],[2,7],[2,8],[2,9], [3,4],[3,5],[3,6],[3,7],[3,8],[3,9], [4,4],[4,5],[4,6],[4,7],[4,8],[4,9], [5,4],[5,9],[6,4],[6,9],[7,4],[7,9],[8,4],[8,9]}; AA[1,5]:=A[4,5]; AA[4,5]:=A[4,8]; AA[4,8]:=A[1,8]; AA[1,8]:=A[1,5]; AA[1,6]:=A[3,5]; AA[3,5]:=A[4,7]; AA[4,7]:=A[2,8]; AA[2,8]:=A[1,6]; AA[1,7]:=A[2,5]; AA[2,5]:=A[4,6]; AA[4,6]:=A[3,8]; AA[3,8]:=A[1,7]; AA[2,6]:=A[3,6]; AA[3,6]:=A[3,7]; AA[3,7]:=A[2,7]; AA[2,7]:=A[2,6]; AA[8,4]:=A[4,4]; AA[4,4]:=A[5,9]; AA[5,9]:=A[1,9]; AA[1,9]:=A[8,4]; AA[7,4]:=A[3,4]; AA[3,4]:=A[6,9]; AA[6,9]:=A[2,9]; AA[2,9]:=A[7,4]; AA[6,4]:=A[2,4]; AA[2,4]:=A[7,9]; AA[7,9]:=A[3,9]; AA[3,9]:=A[6,4]; AA[5,4]:=A[1,4]; AA[1,4]:=A[8,9]; AA[8,9]:=A[4,9]; AA[4,9]:=A[5,4]; for j from 1 to 8 do for k from 1 to 12 do if not(member([j,k],indices)) then AA[j,k]:=A[j,k] fi; od; od; RETURN(AA) end; #move_r1 move_r2 := proc (A) local j, k, AA,indices; AA := matrix(8,12); indices:={[8,3],[4,3],[5,10],[1,10],[7,3],[3,3], [6,10],[2,10],[7,3],[6,3],[2,3],[7,10], [3,10],[6,3],[5,3],[1,3],[8,10],[4,10]}; AA[8,3]:=A[4,3]; AA[4,3]:=A[5,10]; AA[5,10]:=A[1,10]; AA[1,10]:=A[8,3]; AA[7,3]:=A[3,3]; AA[3,3]:=A[6,10]; AA[6,10]:=A[2,10]; AA[2,10]:=A[7,3]; AA[6,3]:=A[2,3]; AA[2,3]:=A[7,10]; AA[7,10]:=A[3,10]; AA[3,10]:=A[6,3]; AA[5,3]:=A[1,3]; AA[1,3]:=A[8,10]; AA[8,10]:=A[4,10]; AA[4,10]:=A[5,3]; for j from 1 to 8 do for k from 1 to 12 do if not(member([j,k],indices)) then AA[j,k]:=A[j,k] fi; od; od; RETURN(AA) end; #move_r2 move_u1 := proc (A) local j, k, AA,indices; AA := matrix(8,12); indices:={[1,1],[1,2],[1,3],[1,4],[1,5], [1,6],[1,7],[1,8],[1,9],[1,10], [1,11],[1,12],[5,1],[5,2],[5,3], [5,4],[5,5],[5,6],[5,7],[5,8], [6,1],[6,2],[6,3],[6,4],[7,1], [7,2],[7,3],[7,4],[8,1],[8,2], [8,3],[8,4]}; AA[1,1]:=A[1,5]; AA[1,2]:=A[1,6]; AA[1,3]:=A[1,7]; AA[1,4]:=A[1,8]; AA[5,5]:=A[1,1]; AA[5,6]:=A[1,2]; AA[5,7]:=A[1,3]; AA[5,8]:=A[1,4]; AA[1,9]:=A[5,5]; AA[1,10]:=A[5,6]; AA[1,11]:=A[5,7]; AA[1,12]:=A[5,8]; AA[1,5]:=A[1,9]; AA[1,6]:=A[1,10]; AA[1,7]:=A[1,11]; AA[1,8]:=A[1,12]; AA[5,1]:=A[8,1]; AA[5,2]:=A[7,1]; AA[7,1]:=A[8,3]; AA[5,3]:=A[6,1]; AA[6,1]:=A[8,2]; AA[5,4]:=A[5,1]; AA[6,4]:=A[5,2]; AA[7,4]:=A[5,3]; AA[8,4]:=A[5,4]; AA[8,1]:=A[8,4]; AA[8,2]:=A[7,4]; AA[8,3]:=A[6,4]; AA[6,2]:=A[7,2]; AA[6,3]:=A[6,2]; AA[7,3]:=A[6,3]; AA[7,2]:=A[7,3]; for j from 1 to 8 do for k from 1 to 12 do if not(member([j,k],indices)) then AA[j,k]:=A[j,k] fi; od; od; RETURN(AA) end; #move_u1 move_u2 := proc (A) local j, k, AA,indices; AA := matrix(8,12); indices:={[2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[2,8], [2,9],[2,10],[2,11],[2,12],[6,5],[6,6],[6,7],[6,8]}; AA[2,1]:=A[2,5]; AA[2,2]:=A[2,6]; AA[2,3]:=A[2,7]; AA[2,4]:=A[2,8]; AA[6,5]:=A[2,1]; AA[6,6]:=A[2,2]; AA[6,7]:=A[2,3]; AA[6,8]:=A[2,4]; AA[2,9]:=A[6,5]; AA[2,10]:=A[6,6]; AA[2,11]:=A[6,7]; AA[2,12]:=A[6,8]; AA[2,5]:=A[2,9]; AA[2,6]:=A[2,10]; AA[2,7]:=A[2,11]; AA[2,8]:=A[2,12]; for j from 1 to 8 do for k from 1 to 12 do if not(member([j,k],indices)) then AA[j,k]:=A[j,k] fi; od; od; RETURN(AA) end; #move_u2 move_l1 := proc (A) local j, k, AA,indices; AA := matrix(8,12); indices:={[1,1],[1,12],[2,1],[2,12],[3,1], [3,12],[4,1],[4,12],[5,1],[5,5], [5,6],[5,7],[5,8],[5,12],[6,1], [6,5],[6,6],[6,7],[6,8],[6,12], [7,1],[7,5],[7,6],[7,7],[7,8], [7,12],[8,1],[8,5],[8,6],[8,7], [8,8],[8,12]}; AA[4,1]:=A[8,1]; AA[8,1]:=A[1,12]; AA[1,12]:=A[5,12]; AA[5,12]:=A[4,1]; AA[3,1]:=A[7,1]; AA[7,1]:=A[2,12]; AA[2,12]:=A[6,12]; AA[6,12]:=A[3,1]; AA[2,1]:=A[6,1]; AA[6,1]:=A[3,12]; AA[3,12]:=A[7,12]; AA[7,12]:=A[2,1]; AA[1,1]:=A[5,1]; AA[5,1]:=A[4,12]; AA[4,12]:=A[8,12]; AA[8,12]:=A[1,1]; AA[5,5]:=A[8,5]; AA[8,5]:=A[8,8]; AA[8,8]:=A[5,8]; AA[5,8]:=A[5,5]; AA[5,6]:=A[7,5]; AA[7,5]:=A[8,7]; AA[8,7]:=A[6,8]; AA[6,8]:=A[5,6]; AA[5,7]:=A[6,5]; AA[6,5]:=A[8,6]; AA[8,6]:=A[7,8]; AA[7,8]:=A[5,7]; AA[6,6]:=A[7,6]; AA[7,6]:=A[7,7]; AA[7,7]:=A[6,7]; AA[6,7]:=A[6,6]; for j from 1 to 8 do for k from 1 to 12 do if not(member([j,k],indices)) then AA[j,k]:=A[j,k] fi; od; od; RETURN(AA) end; #move_l1 move_l2 := proc (A) local j, k, AA,indices; AA := matrix(8,12); indices:={[1,11],[5,11],[4,2],[8,2],[2,11],[6,11],[3,2], [7,2],[3,11],[7,11],[2,2],[6,2],[4,11],[8,11],[1,2],[5,2]}; AA[1,11]:=A[5,11]; AA[5,11]:=A[4,2]; AA[4,2]:=A[8,2]; AA[8,2]:=A[1,11]; AA[2,11]:=A[6,11]; AA[6,11]:=A[3,2]; AA[3,2]:=A[7,2]; AA[7,2]:=A[2,11]; AA[3,11]:=A[7,11]; AA[7,11]:=A[2,2]; AA[2,2]:=A[6,2]; AA[6,2]:=A[3,11]; AA[4,11]:=A[8,11]; AA[8,11]:=A[1,2]; AA[1,2]:=A[5,2]; AA[5,2]:=A[4,11]; for j from 1 to 8 do for k from 1 to 12 do if not(member([j,k],indices)) then AA[j,k]:=A[j,k] fi; od; od; RETURN(AA) end; #move_l2 move_f1 := proc (A) local j, k, AA,indices; AA := matrix(8,12); indices:={[1,1],[1,2],[1,3],[1,4],[1,5], [2,1],[2,2],[2,3],[2,4],[2,5], [3,1],[3,2],[3,3],[3,4],[3,5], [4,1],[4,2],[4,3],[4,4],[4,5], [5,8],[6,8],[7,8],[8,1],[8,2],[8,3], [8,4],[8,8],[8,9],[8,10],[8,11],[8,12]}; AA[1,5]:=A[8,1]; AA[8,1]:=A[8,8]; AA[8,8]:=A[8,9]; AA[8,9]:=A[1,5]; AA[2,5]:=A[8,2]; AA[8,2]:=A[7,8]; AA[7,8]:=A[8,10]; AA[8,10]:=A[2,5]; AA[3,5]:=A[8,3]; AA[8,3]:=A[6,8]; AA[6,8]:=A[8,11]; AA[8,11]:=A[3,5]; AA[4,5]:=A[8,4]; AA[8,4]:=A[5,8]; AA[5,8]:=A[8,12]; AA[8,12]:=A[4,5]; AA[1,4]:=A[1,1]; AA[1,1]:=A[4,1]; AA[4,1]:=A[4,4]; AA[4,4]:=A[1,4]; AA[1,3]:=A[2,1]; AA[2,1]:=A[4,2]; AA[4,2]:=A[3,4]; AA[3,4]:=A[1,3]; AA[1,2]:=A[3,1]; AA[3,1]:=A[4,3]; AA[4,3]:=A[2,4]; AA[2,4]:=A[1,2]; AA[2,2]:=A[3,2]; AA[3,2]:=A[3,3]; AA[3,3]:=A[2,3]; AA[2,3]:=A[2,2]; for j from 1 to 8 do for k from 1 to 12 do if not(member([j,k],indices)) then AA[j,k]:=A[j,k] fi; od; od; RETURN(AA) end; #move_f1 move_f2 := proc (A) local j, k, AA,indices; AA := matrix(8,12); indices:={[1,6],[2,6],[3,6],[4,6],[5,7], [6,7],[7,1],[7,9],[7,2],[7,10], [7,7],[7,3],[7,11],[7,4],[7,12],[8,7]}; AA[1,6]:=A[7,1]; AA[7,9]:=A[1,6]; AA[8,7]:=A[7,9]; AA[7,1]:=A[8,7]; AA[2,6]:=A[7,2]; AA[7,10]:=A[2,6]; AA[7,7]:=A[7,10]; AA[7,2]:=A[7,7]; AA[3,6]:=A[7,3]; AA[7,11]:=A[3,6]; AA[6,7]:=A[7,11]; AA[7,3]:=A[6,7]; AA[4,6]:=A[7,4]; AA[7,12]:=A[4,6]; AA[5,7]:=A[7,12]; AA[7,4]:=A[5,7]; for j from 1 to 8 do for k from 1 to 12 do if not(member([j,k],indices)) then AA[j,k]:=A[j,k] fi; od; od; RETURN(AA) end; #move_f2 move_b1 := proc (A) local j, k, AA,indices; AA := matrix(8,12); indices:={[1,8],[1,9],[1,10],[1,11],[1,12], [2,8],[2,9],[2,10],[2,11],[2,12], [3,8],[3,9],[3,10],[3,11],[3,12], [4,8],[4,9],[4,10],[4,11],[4,12], [5,1],[5,2],[5,3],[5,4],[5,5], [5,9],[5,10],[5,11],[5,12],[6,5], [7,5],[8,5]}; AA[5,5]:=A[5,4]; AA[5,4]:=A[4,8]; AA[4,8]:=A[5,12]; AA[5,12]:=A[5,5]; AA[6,5]:=A[5,3]; AA[5,3]:=A[3,8]; AA[3,8]:=A[5,11]; AA[5,11]:=A[6,5]; AA[7,5]:=A[5,2]; AA[5,2]:=A[2,8]; AA[2,8]:=A[5,10]; AA[5,10]:=A[7,5]; AA[8,5]:=A[5,1]; AA[5,1]:=A[1,8]; AA[1,8]:=A[5,9]; AA[5,9]:=A[8,5]; AA[1,9]:=A[4,9]; AA[4,9]:=A[4,12]; AA[4,12]:=A[1,12]; AA[1,12]:=A[1,9]; AA[1,10]:=A[3,9]; AA[3,9]:=A[4,11]; AA[4,11]:=A[2,12]; AA[2,12]:=A[1,10]; AA[1,11]:=A[2,9]; AA[2,9]:=A[4,10]; AA[4,10]:=A[3,12]; AA[3,12]:=A[1,11]; AA[2,10]:=A[3,10]; AA[3,10]:=A[3,11]; AA[3,11]:=A[2,11]; AA[2,11]:=A[2,10]; for j from 1 to 8 do for k from 1 to 12 do if not(member([j,k],indices)) then AA[j,k]:=A[j,k] fi; od; od; RETURN(AA) end; #move_b1 move_b2 := proc (A) local j, k, AA,indices; AA := matrix(8,12); indices:={[1,7],[2,7],[3,7],[4,7],[5,6], [6,1],[6,2],[6,3],[6,4],[6,6],[7,6], [8,6],[6,9],[6,10],[6,11],[6,12]}; AA[6,12]:=A[5,6]; AA[5,6]:=A[6,4]; AA[6,4]:=A[4,7]; AA[4,7]:=A[6,12]; AA[6,11]:=A[6,6]; AA[6,6]:=A[6,3]; AA[6,3]:=A[3,7]; AA[3,7]:=A[6,11]; AA[6,10]:=A[7,6]; AA[7,6]:=A[6,2]; AA[6,2]:=A[2,7]; AA[2,7]:=A[6,10]; AA[6,9]:=A[8,6]; AA[8,6]:=A[6,1]; AA[6,1]:=A[1,7]; AA[1,7]:=A[6,9]; for j from 1 to 8 do for k from 1 to 12 do if not(member([j,k],indices)) then AA[j,k]:=A[j,k] fi; od; od; RETURN(AA) end; #move_b2 move_d1 := proc (A) local j, k, AA,indices; AA := matrix(8,12); indices:={[4,1],[4,2],[4,3],[4,4],[4,5], [4,6],[4,7],[4,8],[4,9],[4,10], [4,11],[4,12],[5,9],[5,10],[5,11],[5,12], [6,9],[6,10],[6,11],[6,12],[7,9], [7,10],[7,11],[7,12],[8,5],[8,6], [8,7],[8,8],[8,9],[8,10],[8,11],[8,12]}; AA[7,9]:=A[8,11]; AA[8,11]:=A[6,12]; AA[6,12]:=A[5,10]; AA[5,10]:=A[7,9]; AA[6,9]:=A[8,10]; AA[8,10]:=A[7,12]; AA[7,12]:=A[5,11]; AA[5,11]:=A[6,9]; AA[4,8]:=A[4,4]; AA[4,7]:=A[4,3]; AA[4,6]:=A[4,2]; AA[4,5]:=A[4,1]; AA[4,9]:=A[4,5]; AA[4,10]:=A[4,6]; AA[4,11]:=A[4,7]; AA[4,12]:=A[4,8]; AA[8,5]:=A[4,9]; AA[8,6]:=A[4,10]; AA[8,7]:=A[4,11]; AA[8,8]:=A[4,12]; AA[4,1]:=A[8,5]; AA[4,2]:=A[8,6]; AA[4,3]:=A[8,7]; AA[4,4]:=A[8,8]; AA[5,12]:=A[5,9]; AA[5,9]:=A[8,9]; AA[8,9]:=A[8,12]; AA[8,12]:=A[5,12]; AA[6,11]:=A[6,10]; AA[6,10]:=A[7,10]; AA[7,10]:=A[7,11]; AA[7,11]:=A[6,11]; for j from 1 to 8 do for k from 1 to 12 do if not(member([j,k],indices)) then AA[j,k]:=A[j,k] fi; od; od; RETURN(AA) end; #move_d1 move_d2 := proc (A) local j, k, AA,indices; AA := matrix(8,12); indices:={[7,5],[7,6],[7,7],[7,8],[3,1],[3,2],[3,3],[3,4], [3,5],[3,6],[3,7],[3,8],[3,9],[3,10],[3,11],[3,12], [7,5],[7,6],[7,7],[7,8]}; AA[7,5]:=A[3,9]; AA[7,6]:=A[3,10]; AA[7,7]:=A[3,11]; AA[7,8]:=A[3,12]; AA[3,5]:=A[3,1]; AA[3,6]:=A[3,2]; AA[3,7]:=A[3,3]; AA[3,8]:=A[3,4]; AA[3,9]:=A[3,5]; AA[3,10]:=A[3,6]; AA[3,11]:=A[3,7]; AA[3,12]:=A[3,8]; AA[3,1]:=A[7,5]; AA[3,2]:=A[7,6]; AA[3,3]:=A[7,7]; AA[3,4]:=A[7,8]; for j from 1 to 8 do for k from 1 to 12 do if not(member([j,k],indices)) then AA[j,k]:=A[j,k] fi; od; od; RETURN(AA) end; #move_d2 move_power:=proc(g,A) local i,j,AA,generators,gen,power; generators:={R1,R2,L1,L2,U1,U2,D1,D2,F1,F2,B1,B2}; AA:=A; if type(g,`^`) then gen:=op(1,g); power:=op(2,g) mod 4; else if member(g,generators) then gen:=g; power:=1; fi; fi; if g=1 then RETURN(AA); fi; for i from 1 to power do if gen=R1 then AA:=move_r1(AA) fi; if gen=R2 then AA:=move_r2(AA) fi; if gen=L1 then AA:=move_l1(AA) fi; if gen=L2 then AA:=move_l2(AA) fi; if gen=U1 then AA:=move_u1(AA) fi; if gen=U2 then AA:=move_u2(AA) fi; if gen=D1 then AA:=move_d1(AA) fi; if gen=D2 then AA:=move_d2(AA) fi; if gen=F1 then AA:=move_f1(AA) fi; if gen=F2 then AA:=move_f2(AA) fi; if gen=B1 then AA:=move_b1(AA) fi; if gen=B2 then AA:=move_b2(AA) fi; od; RETURN(AA); end; move:=proc(w,A) local i,AA,generators; generators:={R1,R2,U1,U2,F1,F2,D1,D2,L1,L2,B1,B2}; AA:=A; if type(w,`^`) then AA:=move_power(w,AA); fi; if w=1 then RETURN(AA); fi; if member(w,generators) then AA:=move_power(w,AA); fi; if type(w,list) then for i from 1 to nops(w) do AA:=move_power(op(i,w),AA); od; fi; RETURN(AA); end; rc := proc (L, A) local AA, LL; AA := move(L,A); LL := cube_draw(AA); display3d(LL) end;