# 3x3 Rubik's Cube (c) Istvan T. Hernadvolgyi 1995 Read("/home/math6/wdj/gap/new/AbStab.g"); # My very first gap function! generate corners from indecies # GenerateCorners := function(cube,cornerIndecies) local i,j, # loop counters cell, # the three visible sides of a corner list; # the list that will hold all corners list := []; # initialize list to [] for i in [1..Length(cornerIndecies)] # for all 8 corners do cell := []; for j in [1..Length(cornerIndecies[i])] # for all 3 "sides" of a corner do Add(cell,cube[cornerIndecies[i][j]]); # map index to "sticker" number od; # for j Add(list,cell); # add cell to list od; # for i return list; # return list holding corners end; # function # first use of function! print out all the corners of the cube # Print("\nCorners: ",GenerateCorners(orbits[1],corners),"\n\n"); ################################################################### # # # # # +--------------+ # | 1 2 3 | # | 4 top 5 | # | 6 7 8 | # +--------------+--------------+--------------+--------------+ # | 9 10 11 | 17 18 19 | 25 26 27 | 33 34 35 | # | 12 left 13 | 20 front 21 | 28 right 29 | 36 rear 37 | # | 14 15 16 | 22 23 24 | 30 31 32 | 38 39 40 | # +--------------+--------------+--------------+--------------+ # | 41 42 43 | # | 44 bottom 45 | # | 46 47 48 | # +--------------+ # ################################################################### # Some random positions from the 3x3x3 Rubik's Cube # Print("\nOperations on the 3x3x3 Rubik's Cube\n"); Print("\n(c) Hernadvolgyi 1995\n\n"); Print("\ntype gap>info(); to obtain information on the functions\n\n"); info := function() Print("\nOperations on the 3x3x3 Rubik's Cube\n"); Print("\n(c) Hernadvolgyi 1995\n\n"); Print("Functions Implemented: \n\n"); Print(" - CubeList(,)\n"); Print(" where:\n"); Print(" >the First argument is a permuted list on [1..48]\n"); Print(" >the Second argument is *one* or a *list* of the \n"); Print(" following predifined operations: \n"); Print(" left,top,right,bottom,rear,front \n\n"); Print(" example:\n"); Print(" >c1 := CubeList(cubelist,left);\n"); Print(" >c2 := CubeList(cubelist,[left,right,bottom^-1,top^-1]);\n"); Print(" >c2 := CubeList(c2,[left^-3,bottom^5]);\n\n"); Print(" note that cubelist is a predifined constant representing \n"); Print(" the 'solved' cube.\n\n"); Print(" - DrawCube(,);\n"); Print(" where:\n"); Print(" >the First argument is a permuted list on [1..48]\n"); Print(" >the Second argument is 'LabelPrint' or 'FormatPrint'\n"); Print(" LabelPrint draws the cube's sides by *color*\n"); Print(" while FormatPrint dispalys the label-numbers\n\n"); Print(" example:\n"); Print(" >c1 := CubeList(cubelist,left);\n"); Print(" >DrawCube(c1,LabelPrint); # cube^left by LabelPrint\n"); Print(" >DrawCube(c1,FormatPrint); # cube^left by FormatPrint\n"); Print(" >DrawCube(cubelist,LabelPrint); # the original cube\n\n"); end; # info # predifined operators # # ex: top means rotating the *top* side of the cube clockwise top := ( 1, 3, 8, 6)( 2, 5, 7, 4)( 9,33,25,17)(10,34,26,18)(11,35,27,19);; left := ( 9,11,16,14)(10,13,15,12)( 1,17,41,40)( 4,20,44,37)( 6,22,46,35);; front := (17,19,24,22)(18,21,23,20)( 6,25,43,16)( 7,28,42,13)( 8,30,41,11);; right := (25,27,32,30)(26,29,31,28)( 3,38,43,19)( 5,36,45,21)( 8,33,48,24);; rear := (33,35,40,38)(34,37,39,36)( 3, 9,46,32)( 2,12,47,29)( 1,14,48,27);; bottom:= (41,43,48,46)(42,45,47,44)(14,22,30,38)(15,23,31,39)(16,24,32,40);; # # cube := Group( # ( 1, 3, 8, 6)( 2, 5, 7, 4)( 9,33,25,17)(10,34,26,18)(11,35,27,19), # ( 9,11,16,14)(10,13,15,12)( 1,17,41,40)( 4,20,44,37)( 6,22,46,35), # (17,19,24,22)(18,21,23,20)( 6,25,43,16)( 7,28,42,13)( 8,30,41,11), # (25,27,32,30)(26,29,31,28)( 3,38,43,19)( 5,36,45,21)( 8,33,48,24), # (33,35,40,38)(34,37,39,36)( 3, 9,46,32)( 2,12,47,29)( 1,14,48,27), # (41,43,48,46)(42,45,47,44)(14,22,30,38)(15,23,31,39)(16,24,32,40) # ); cube := Group( top, left, front, right, rear, bottom);; cube.nameOfOperations := [ "top", "left", "front", "right", "rear", "bottom" ];; cube.abstractGenerators := [ AbstractGenerator("top"), AbstractGenerator("left"), AbstractGenerator("front"), AbstractGenerator("right"), AbstractGenerator("rear"), AbstractGenerator("bottom"), ]; Print("\n Size of Search space of 3x3x3 Cube: ",Size(cube),"\n\n"); cubelist := [ 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12, 13,14,15,16,17,18,19,20,21,22,23,24, 25,26,27,28,29,30,31,32,33,34,35,36, 37,38,39,40,41,42,43,44,45,46,47,48 ]; # the *solved* cube cube.solved := cubelist; FormatPrint := function(number) if number>9 then Print(number); else Print(" ",number); fi; end; # FormatPrint LabelPrint := function(number) if number< 9 then Print("TO"); elif number<17 then Print("LE"); elif number<25 then Print("FR"); elif number<33 then Print("RI"); elif number<41 then Print("RE"); elif number<49 then Print("BO"); fi; end; # LabelPrint DrawCube := function(asList,func) local i; Print("\n"); Print(" +--------------+\n"); Print(" | "); func(asList[1]);Print(" "); func(asList[2]);Print(" "); func(asList[3]);Print(" |\n"); Print(" | "); func(asList[4]);Print(""); if func = FormatPrint then Print(" top "); else Print(" TO "); fi; func(asList[5]);Print(" |\n"); Print(" | "); func(asList[6]);Print(" "); func(asList[7]);Print(" "); func(asList[8]);Print(" |\n"); Print("+--------------+--------------+--------------+--------------+\n"); Print("| "); func(asList[ 9]);Print(" "); func(asList[10]);Print(" "); func(asList[11]);Print(" | "); func(asList[17]);Print(" "); func(asList[18]);Print(" "); func(asList[19]);Print(" | "); func(asList[25]);Print(" "); func(asList[26]);Print(" "); func(asList[27]);Print(" | "); func(asList[33]);Print(" "); func(asList[34]);Print(" "); func(asList[35]);Print(" |\n"); Print("| "); func(asList[12]);Print(""); if func = FormatPrint then Print(" left "); else Print(" LE "); fi; func(asList[13]);Print(" | "); func(asList[20]);Print(""); if func = FormatPrint then Print(" front "); else Print(" FR "); fi; func(asList[21]);Print(" | "); func(asList[28]);Print(""); if func = FormatPrint then Print(" right "); else Print(" RI "); fi; func(asList[29]);Print(" | "); func(asList[36]);Print(""); if func = FormatPrint then Print(" rear "); else Print(" RE "); fi; func(asList[37]);Print(" |\n"); Print("| "); func(asList[14]);Print(" "); func(asList[15]);Print(" "); func(asList[16]);Print(" | "); func(asList[22]);Print(" "); func(asList[23]);Print(" "); func(asList[24]);Print(" | "); func(asList[30]);Print(" "); func(asList[31]);Print(" "); func(asList[32]);Print(" | "); func(asList[38]);Print(" "); func(asList[39]);Print(" "); func(asList[40]);Print(" |\n"); Print("+--------------+--------------+--------------+--------------+\n"); Print(" | "); func(asList[41]);Print(" "); func(asList[42]);Print(" "); func(asList[43]);Print(" |\n"); Print(" | "); func(asList[44]);Print(""); if func = FormatPrint then Print(" bottom "); else Print(" BO "); fi; func(asList[45]);Print(" |\n"); Print(" | "); func(asList[46]);Print(" "); func(asList[47]);Print(" "); func(asList[48]);Print(" |\n"); Print(" +--------------+\n"); end; # DrawCube NameOfOperation := function(object,Oper) local Pos; Pos := Position(object.generators,Oper); if Pos<>false then return object.nameOfOperations[Pos]; else return ConcatenationString (NameOfOperation(object,Oper^-1)," reverse"); fi; end; # NameOfOperation OperationOnList := function(theList,Original,Oper,showList,object) local i, list, Result; Result := []; if IsList(Oper)=false then list := List(Original,x->x^Oper); for i in [1..Length(Original)] do Result[i] := theList[Position(list,i)]; od; if showList then DrawCube(Result,LabelPrint); Print(" ^ \n | Operation: ",NameOfOperation(object,Oper),"\n\n"); fi; else Result := Copy(theList); for i in [1..Length(Oper)] do Result := OperationOnList(Result,Original,Oper[i],showList,object); od; fi; return Result; end; # OperationOnList CubeList := function(theList,Oper,object) local i, list; list :=Copy(theList); if IsList(Oper) then for i in [1..Length(Oper)] do list := OperationOnList(list,cubelist,Oper[i],true,object); od; else list := OperationOnList(list,cubelist,Oper,true,object); fi; return list; # list end; # CubeList Generator := function(object,word) local Result; Result := Position(object.abstractGenerators,word); if Result<>false then return object.generators[Result]; else return object.generators[Position(object.abstractGenerators,word^-1)]^-1; fi; end; # Generator GeneratorListFromWord := function(word,object) local i, l, Result; l := List(word); Result := []; for i in [1..Length(l)] do Add(Result,Generator(object,l[i])); od; return Result; end; # GeneratorListFromWord SolutionOperations := function(list) local i, Result; Result := []; for i in Reversed([1..Length(list)]) do Add(Result,list[i]^-1); od; return Result; end; # SolutionOperations Randomize := function(object) local i, length, newList, random, Result; if IsBound(object.RandomOperationList) = false then object.RandomOperationList := []; object.ReducedRandomOperationList := []; fi; length := Random([1..15]); newList := []; Result := (); for i in [1..length] do random := Random(object.generators); Add(newList,random); Result := Result*random; od; Add(object.RandomOperationList,newList); Add(object.ReducedRandomOperationList,Result); return Result; end; # Randomize GiveSolutionPath := function(object,index,n) local word, list, counter, last, Ok; Print("\n I am working ! \n"); word := FactorPermGroupElement (object,object.ReducedRandomOperationList[index]); last := LengthWord(word); counter := 1; Ok := true; while counter