Created
July 12, 2022 22:05
-
-
Save btownrippleman/d97402e70d56017eee3b4f7ebfe1aa02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "time" | |
| ) | |
| // parallelization := 4 | |
| var cubeMaps = map[string][]int {"x": {1, 2, 6, 5}, "y": {3,7,6,2}, "z": {0, 1, 2, 3}} | |
| var faces2rotatePairs = map[string]map[int]int { "x": {2:1,1:2,0:0}, "y": {2:0,0:2,1:1}, "z": {1:0,0:1,2:2}} | |
| var start = time.Now() | |
| var configurations = new([6000000][8][3]int) | |
| var hashArray = new([6000000]string) | |
| var initial_config = [8][3]int{{0, 1, 2}, {3, 1, 2}, {3, 5, 2}, {0, 5, 2}, {0, 1, 4}, {3, 1, 4}, {3, 5, 4}, {0, 5, 4}} | |
| var newConfig = initial_config | |
| var newHash = "" | |
| var exist = true | |
| var mapOfExistingConfigurations = make(map[string]string) | |
| var lo = 0 | |
| var hi = 1 | |
| var numrotations = 1 | |
| var newIndex = hi | |
| var axes = []string {"x","y","z"} | |
| var newConfigsProduced = true | |
| func main() { | |
| mapOfExistingConfigurations[genHash(initial_config)] = "0" | |
| hashArray[0] = genHash(initial_config) | |
| configurations[0] = initial_config | |
| for newConfigsProduced { | |
| newConfigsProduced = false | |
| checkEachConfiguration() | |
| newConfigsProduced = newConfigsProduced || newIndex !=hi | |
| fmt.Println(fmt.Sprint(numrotations), "rotations yields", fmt.Sprint(newIndex-hi), "new configurations computed in", time.Since(start)) | |
| lo = hi | |
| hi = newIndex | |
| numrotations += 1 | |
| } | |
| fmt.Println("time passed: ", time.Since(start)," with ", newIndex," different configurations total") | |
| } | |
| func checkEachConfiguration() map[string]string { | |
| directions := [2]int{-1,1} | |
| for lo != hi { | |
| for _, axis := range axes { | |
| for _, direction := range directions { | |
| newConfig := rotate(configurations[lo], axis,direction) | |
| newHash := genHash(newConfig) | |
| _, exist := mapOfExistingConfigurations[newHash] | |
| mapOfExistingConfigurations[newHash] = "0" //existingHash + axis + fmt.Sprint(direction) | |
| hashArray[newIndex] = newHash | |
| configurations[newIndex] = newConfig | |
| newIndex += B2i(!exist) | |
| } | |
| } | |
| lo = lo + 1 | |
| } | |
| return mapOfExistingConfigurations | |
| } | |
| func B2i(b bool) int { | |
| if b { | |
| return 1 | |
| } | |
| return 0 | |
| } | |
| func rotate(inM [8][3]int, axis string, direction int ) [8][3]int { | |
| outM := inM | |
| cubeMap := cubeMaps[axis] | |
| faceMap := faces2rotatePairs[axis] | |
| for i:=0; i < 4; i++{ | |
| for k:=0; k < 3; k++ { | |
| outM[cubeMap[(i+direction+4)%4]][faceMap[k]] = inM[cubeMap[i]][k] | |
| } | |
| } | |
| return outM | |
| } | |
| func genHash(arr [8][3]int) string { | |
| return fmt.Sprint(arr) | |
| // return fmt.Sprint(arr[0][0])+fmt.Sprint(arr[0][1])+fmt.Sprint(arr[0][2])+fmt.Sprint(arr[1][0])+fmt.Sprint(arr[1][1])+fmt.Sprint(arr[1][2])+fmt.Sprint(arr[2][0])+fmt.Sprint(arr[2][1])+fmt.Sprint(arr[2][2])+fmt.Sprint(arr[3][0])+fmt.Sprint(arr[3][1])+fmt.Sprint(arr[3][2])+fmt.Sprint(arr[4][0])+fmt.Sprint(arr[4][1])+fmt.Sprint(arr[4][2])+fmt.Sprint(arr[5][0])+fmt.Sprint(arr[5][1])+fmt.Sprint(arr[5][2])+fmt.Sprint(arr[6][0])+fmt.Sprint(arr[6][1])+fmt.Sprint(arr[6][2])+fmt.Sprint(arr[7][0])+fmt.Sprint(arr[7][1])+fmt.Sprint(arr[7][2]); | |
| // outString := ""; for i := range arr { for _, j:= range arr[i] { outString += fmt.Sprint(j)}} | |
| // return outString | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment