fork download
  1. algs = ["",
  2. "R' U R' U' R' U' R' U R U R2",
  3. "R U' R U R U R U' R' U' R2",
  4. "R2 U2 R U2 R2 U2 R2 U2 R U2 R2",
  5. "R2 U R2 U' R2 F2 R2 U' F2 U R2 F2",
  6. "R U' R F2 R' U R' U' R2 F2 R2",
  7. "R2 F2 R2 U R U' R F2 R' U R'",
  8. "R U R' U R' U' R F' R U R' U' R' F R2 U' R2 U R",
  9. "F' U2 R' U F U' F' U' R U' F",
  10. "R U R' F' R U R' U' R' F R2 U' R'",
  11. "R' U2 R U2 R' F R U R' U' R' F' R2",
  12. "F' R' U' R F' R' U F' U' F' U F R F2",
  13. "F2 R2 U' R' U' R F2 R' U R F2 U R2 F2",
  14. "F2 R2 U' F2 R' U' R F2 R' U R U R2 F2",
  15. "R' U' R2 U' R2 U' R U2 R2 F U R' U' R F' R",
  16. "R' F R' U R U' F' R2 U2 R' U R2 U R2 U R",
  17. "F' R U R' U' R' F R2 F U' R' U' R U F' R'",
  18. "R' U R' F R F' R U' R' F' U F R U R' U' R",
  19. "R U R' U' R' F R2 U' R' U' R U R' F'",
  20. "F R U' R' U' R U R' F' R U R' U' R' F R F'",
  21. "F' U2 F' U' R' F' R2 U' R' U R' F R U' F",
  22. "R U' R U F R F2 U F U' F R' F' R'"]
  23.  
  24.  
  25. algDict = {0: '0 ', 1: 'U ', 2: 'U ', 3: 'H ', 4: 'Z ', 5: 'A ',
  26. 6: 'A ', 7: 'E ', 8: 'J ', 9: 'J ', 10: 'R ', 11: 'R ',
  27. 12: 'G ', 13: 'G ', 14: 'G ', 15: 'G ', 16: 'N ', 17: 'N ',
  28. 18: 'T ', 19: 'Y ', 20: 'F ', 21: 'V '}
  29. ##################################################
  30. class MyCube:
  31. """A virtual 3x3x3 matrix"""
  32. def __init__(self):
  33. self.uSide = ['U', 'U', 'U', 'U', 'U', 'U', 'U', 'U'] #URF, UF, etc
  34. self.fSide = ['F', 'F', 'F', 'F', 'F', 'F', 'F', 'F'] #FRD, FD, etc
  35. self.lSide = ['L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'] #LFD, LD, etc
  36. self.bSide = ['B', 'B', 'B', 'B', 'B', 'B', 'B', 'B'] #BRD, BD, etc
  37. self.rSide = ['R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'] #RBD, RD, etc
  38. self.dSide = ['D', 'D', 'D', 'D', 'D', 'D', 'D', 'D'] #DBR, DR, etc
  39.  
  40.  
  41. def doU(self):
  42.  
  43. self.uSide[0], self.uSide[1], self.uSide[2], self.uSide[3], self.uSide[4], self.uSide[5], self.uSide[6], self.uSide[7] = self.uSide[6], self.uSide[7], self.uSide[0], self.uSide[1], self.uSide[2], self.uSide[3], self.uSide[4], self.uSide[5]
  44.  
  45. self.fSide[5], self.lSide[5], self.bSide[1], self.rSide[5] = self.rSide[5], self.fSide[5], self.lSide[5], self.bSide[1]
  46. self.fSide[6], self.lSide[6], self.bSide[2], self.rSide[6] = self.rSide[6], self.fSide[6], self.lSide[6], self.bSide[2]
  47. self.fSide[7], self.lSide[7], self.bSide[3], self.rSide[7] = self.rSide[7], self.fSide[7], self.lSide[7], self.bSide[3]
  48.  
  49. def doUp(self):
  50. self.uSide[6], self.uSide[7], self.uSide[0], self.uSide[1], self.uSide[2], self.uSide[3], self.uSide[4], self.uSide[5] = self.uSide[0], self.uSide[1], self.uSide[2], self.uSide[3], self.uSide[4], self.uSide[5], self.uSide[6], self.uSide[7]
  51.  
  52. self.rSide[5], self.fSide[5], self.lSide[5], self.bSide[1] = self.fSide[5], self.lSide[5], self.bSide[1], self.rSide[5]
  53. self.rSide[6], self.fSide[6], self.lSide[6], self.bSide[2] = self.fSide[6], self.lSide[6], self.bSide[2], self.rSide[6]
  54. self.rSide[7], self.fSide[7], self.lSide[7], self.bSide[3] = self.fSide[7], self.lSide[7], self.bSide[3], self.rSide[7]
  55.  
  56. def doR(self):
  57.  
  58. self.rSide[0], self.rSide[1], self.rSide[2], self.rSide[3], self.rSide[4], self.rSide[5], self.rSide[6], self.rSide[7] = self.rSide[6], self.rSide[7], self.rSide[0], self.rSide[1], self.rSide[2], self.rSide[3], self.rSide[4], self.rSide[5]
  59.  
  60. self.fSide[7], self.uSide[7], self.bSide[7], self.dSide[7] = self.dSide[7], self.fSide[7], self.uSide[7], self.bSide[7]
  61. self.fSide[0], self.uSide[0], self.bSide[0], self.dSide[0] = self.dSide[0], self.fSide[0], self.uSide[0], self.bSide[0]
  62. self.fSide[1], self.uSide[1], self.bSide[1], self.dSide[1] = self.dSide[1], self.fSide[1], self.uSide[1], self.bSide[1]
  63.  
  64. def doRp(self):
  65. self.rSide[6], self.rSide[7], self.rSide[0], self.rSide[1], self.rSide[2], self.rSide[3], self.rSide[4], self.rSide[5] = self.rSide[0], self.rSide[1], self.rSide[2], self.rSide[3], self.rSide[4], self.rSide[5], self.rSide[6], self.rSide[7]
  66.  
  67. self.dSide[7], self.fSide[7], self.uSide[7], self.bSide[7] = self.fSide[7], self.uSide[7], self.bSide[7], self.dSide[7]
  68. self.dSide[0], self.fSide[0], self.uSide[0], self.bSide[0] = self.fSide[0], self.uSide[0], self.bSide[0], self.dSide[0]
  69. self.dSide[1], self.fSide[1], self.uSide[1], self.bSide[1] = self.fSide[1], self.uSide[1], self.bSide[1], self.dSide[1]
  70.  
  71. def doF(self):
  72. self.fSide[0], self.fSide[1], self.fSide[2], self.fSide[3], self.fSide[4], self.fSide[5], self.fSide[6], self.fSide[7] = self.fSide[6], self.fSide[7], self.fSide[0], self.fSide[1], self.fSide[2], self.fSide[3], self.fSide[4], self.fSide[5]
  73.  
  74. self.uSide[1], self.rSide[3], self.dSide[5], self.lSide[7] = self.lSide[7], self.uSide[1], self.rSide[3], self.dSide[5]
  75. self.uSide[2], self.rSide[4], self.dSide[6], self.lSide[0] = self.lSide[0], self.uSide[2], self.rSide[4], self.dSide[6]
  76. self.uSide[3], self.rSide[5], self.dSide[7], self.lSide[1] = self.lSide[1], self.uSide[3], self.rSide[5], self.dSide[7]
  77.  
  78. def doFp(self):
  79. self.fSide[6], self.fSide[7], self.fSide[0], self.fSide[1], self.fSide[2], self.fSide[3], self.fSide[4], self.fSide[5] = self.fSide[0], self.fSide[1], self.fSide[2], self.fSide[3], self.fSide[4], self.fSide[5], self.fSide[6], self.fSide[7]
  80.  
  81. self.lSide[7], self.uSide[1], self.rSide[3], self.dSide[5] = self.uSide[1], self.rSide[3], self.dSide[5], self.lSide[7]
  82. self.lSide[0], self.uSide[2], self.rSide[4], self.dSide[6] = self.uSide[2], self.rSide[4], self.dSide[6], self.lSide[0]
  83. self.lSide[1], self.uSide[3], self.rSide[5], self.dSide[7] = self.uSide[3], self.rSide[5], self.dSide[7], self.lSide[1]
  84.  
  85.  
  86.  
  87. def doAlg(self, algString):
  88. ialg = algString.replace('(', '') #get rid of unwanted
  89. ialg = ialg.replace(')', '') # or otherwise unneeded characters
  90. ialg = ialg.replace("2'", '2') # incl. whitespace, paren., 2's
  91. ialg = ialg.replace(' ', ' ')
  92. parts = ialg.split(' ') #Divide the alg up into individual moves
  93.  
  94. for part in parts:
  95. if part == 'U': self.doU()
  96. elif part == 'U2': self.doU(); self.doU()
  97. elif part == "U'": self.doUp()
  98.  
  99. elif part == 'F': self.doF()
  100. elif part == 'F2': self.doF(); self.doF()
  101. elif part == "F'": self.doFp()
  102.  
  103. elif part == 'R': self.doR()
  104. elif part == 'R2': self.doR(); self.doR()
  105. elif part == "R'": self.doRp()
  106.  
  107. def printCube(self):
  108. print
  109. print " ", self.bSide[5] + self.bSide[6] + self.bSide[7]
  110. print " ", self.bSide[4] + "b" + self.bSide[0]
  111. print " ", self.bSide[3] + self.bSide[2] + self.bSide[1] + '\n'
  112.  
  113. print " ", self.uSide[5] + self.uSide[6] + self.uSide[7]
  114. print " ", self.uSide[4] + "u" + self.uSide[0]
  115. print " ", self.uSide[3] + self.uSide[2] + self.uSide[1] + '\n'
  116.  
  117. print "" + self.lSide[5] + self.lSide[6] + self.lSide[7], self.fSide[5] + self.fSide[6] + self.fSide[7], self.rSide[5] + self.rSide[6] + self.rSide[7]
  118. print "" + self.lSide[4] + 'l' + self.lSide[0], self.fSide[4] + 'f' + self.fSide[0], self.rSide[4] + 'r' + self.rSide[0]
  119. print "" + self.lSide[3] + self.lSide[2] + self.lSide[1], self.fSide[3] + self.fSide[2] + self.fSide[1], self.rSide[3] + self.rSide[2] + self.rSide[1] + '\n'
  120.  
  121. print " ", self.dSide[5] + self.dSide[6] + self.dSide[7]
  122. print " ", self.dSide[4] + "d" + self.dSide[0]
  123. print " ", self.dSide[3] + self.dSide[2] + self.dSide[1] + '\n'
  124.  
  125. def printMin(self):
  126. print
  127.  
  128. print " ", self.bSide[3] + self.bSide[2] + self.bSide[1] + '\n'
  129.  
  130. print " ", self.uSide[5] + self.uSide[6] + self.uSide[7]
  131. print " ", self.uSide[4] + "u" + self.uSide[0]
  132. print " ", self.uSide[3] + self.uSide[2] + self.uSide[1] + '\n'
  133.  
  134. print "" + self.lSide[5] + self.lSide[6] + self.lSide[7], self.fSide[5] + self.fSide[6] + self.fSide[7], self.rSide[5] + self.rSide[6] + self.rSide[7]
  135.  
  136. def checkSolved(self):
  137. if self.uSide[0] == self.uSide[1] == self.uSide[2] == self.uSide[3] == self.uSide[4] == self.uSide[5] == self.uSide[6] == self.uSide[7]:
  138. if self.fSide[5] == self.fSide[6] == self.fSide[7]:
  139. if self.lSide[5] == self.lSide[6] == self.lSide[7]:
  140. if self.rSide[5] == self.rSide[6] == self.rSide[7]:
  141. if self.bSide[3] == self.bSide[2] == self.bSide[1]:
  142. return True
  143. return False
  144. ##################################################
  145.  
  146. def tryOne(aTemp, this): #string of alg trying, string of alg trying to solve
  147. wtf = MyCube(); wtf.doAlg(this); wtf.doUp()
  148. for try1 in range(4):
  149. wtf.doU(); wtf2 = wtf
  150. wtf2.doAlg(aTemp)
  151.  
  152. if wtf2.checkSolved(): return True
  153.  
  154. return False
  155.  
  156. def tryTwo(aTemp, bTemp, this):
  157. now = MyCube(); now.doAlg(this); now.doUp()
  158. for try1 in range(4):
  159. now.doU(); mow = now
  160. mow.doAlg(aTemp)
  161. for try2 in range(4):
  162. mow.doU(); oow = mow
  163. oow.doAlg(bTemp)
  164. if oow.checkSolved(): return True
  165.  
  166. return False
  167.  
  168. def tryCombo(a, b, c, listNow):
  169. for alg in range(0, len(algs)):
  170. if listNow[alg] == False:
  171.  
  172. aCube = MyCube(); aCube.doAlg(algs[alg])
  173.  
  174. if aCube.checkSolved(): #basically, check if it's already good (case algs[0])
  175. listNow[alg] = True; continue
  176.  
  177. elif tryOne(a, algs[alg]): listNow[alg] = True; continue
  178. elif tryOne(b, algs[alg]): listNow[alg] = True; continue
  179. elif tryOne(c, algs[alg]): listNow[alg] = True; continue
  180.  
  181. elif tryTwo(a, a, algs[alg]): listNow[alg] = True; continue
  182. elif tryTwo(b, b, algs[alg]): listNow[alg] = True; continue
  183. elif tryTwo(c, c, algs[alg]): listNow[alg] = True; continue
  184.  
  185. elif tryTwo(a, b, algs[alg]): listNow[alg] = True; continue
  186. elif tryTwo(a, c, algs[alg]): listNow[alg] = True; continue
  187.  
  188. elif tryTwo(b, a, algs[alg]): listNow[alg] = True; continue
  189. elif tryTwo(b, c, algs[alg]): listNow[alg] = True; continue
  190.  
  191. elif tryTwo(c, a, algs[alg]): listNow[alg] = True; continue
  192. elif tryTwo(c, b, algs[alg]): listNow[alg] = True; continue
  193.  
  194. else: return listNow
  195.  
  196. return listNow
  197. ##################################################
  198. ## Memo 3 algs? ##
  199.  
  200. highest = 0
  201.  
  202. for l1 in range(1,7):
  203. #print "L1: ", l1
  204. for l2 in range(l1+1,len(algs)):
  205. for l3 in range(l2+1,len(algs)):
  206.  
  207. algsDone = [False]*len(algs)
  208.  
  209. algsDone = tryCombo(algs[l1], algs[l2], algs[l3], algsDone)
  210.  
  211. if sum(algsDone) == len(algs):
  212. print "\t\tAlgs used: ", l1, l2, l3
  213. #print "\t\tCases solved: " + str(sum(algsDone)) + " out of " + str(len(algs))
  214. #print "\t\t", algsDone; print
  215. highest = sum(algsDone)
  216. print '\n\n'
  217.  
Time limit exceeded #stdin #stdout -1s 7176KB
stdin
Standard input is empty
stdout

Standard output is empty