fork download
  1. import time
  2. start = time.time()
  3.  
  4. algs = ["",
  5. "R' U R' U' R' U' R' U R U R2",
  6. "R U' R U R U R U' R' U' R2",
  7. "R2 U2 R U2 R2 U2 R2 U2 R U2 R2",
  8. "R2 U R2 U' R2 F2 R2 U' F2 U R2 F2",
  9. "R U' R F2 R' U R' U' R2 F2 R2",
  10. "R2 F2 R2 U R U' R F2 R' U R'",
  11. "R U R' U R' U' R F' R U R' U' R' F R2 U' R2 U R",
  12. "F' U2 R' U F U' F' U' R U' F",
  13. "R U R' F' R U R' U' R' F R2 U' R'",
  14. "R' U2 R U2 R' F R U R' U' R' F' R2",
  15. "F' R' U' R F' R' U F' U' F' U F R F2",
  16. "F2 R2 U' R' U' R F2 R' U R F2 U R2 F2",
  17. "F2 R2 U' F2 R' U' R F2 R' U R U R2 F2",
  18. "R' U' R2 U' R2 U' R U2 R2 F U R' U' R F' R",
  19. "R' F R' U R U' F' R2 U2 R' U R2 U R2 U R",
  20. "F' R U R' U' R' F R2 F U' R' U' R U F' R'",
  21. "R' U R' F R F' R U' R' F' U F R U R' U' R",
  22. "R U R' U' R' F R2 U' R' U' R U R' F'",
  23. "F R U' R' U' R U R' F' R U R' U' R' F R F'",
  24. "F' U2 F' U' R' F' R2 U' R' U R' F R U' F",
  25. "R U' R U F R F2 U F U' F R' F' R'"]
  26. ##################################################
  27. class MyCube:
  28. """A virtual 3x3x3 matrix"""
  29. def __init__(self):
  30. self.uSide = ['U', 'U', 'U', 'U', 'U', 'U', 'U', 'U'] #URF, UF, etc
  31. self.fSide = ['F', 'F', 'F', 'F', 'F', 'F', 'F', 'F'] #FRD, FD, etc
  32. self.lSide = ['L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'] #LFD, LD, etc
  33. self.bSide = ['B', 'B', 'B', 'B', 'B', 'B', 'B', 'B'] #BRD, BD, etc
  34. self.rSide = ['R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'] #RBD, RD, etc
  35. self.dSide = ['D', 'D', 'D', 'D', 'D', 'D', 'D', 'D'] #DBR, DR, etc
  36.  
  37.  
  38. def doU(self):
  39.  
  40. 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]
  41.  
  42. self.fSide[5], self.lSide[5], self.bSide[1], self.rSide[5] = self.rSide[5], self.fSide[5], self.lSide[5], self.bSide[1]
  43. self.fSide[6], self.lSide[6], self.bSide[2], self.rSide[6] = self.rSide[6], self.fSide[6], self.lSide[6], self.bSide[2]
  44. self.fSide[7], self.lSide[7], self.bSide[3], self.rSide[7] = self.rSide[7], self.fSide[7], self.lSide[7], self.bSide[3]
  45.  
  46. def doUp(self):
  47. 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]
  48.  
  49. self.rSide[5], self.fSide[5], self.lSide[5], self.bSide[1] = self.fSide[5], self.lSide[5], self.bSide[1], self.rSide[5]
  50. self.rSide[6], self.fSide[6], self.lSide[6], self.bSide[2] = self.fSide[6], self.lSide[6], self.bSide[2], self.rSide[6]
  51. self.rSide[7], self.fSide[7], self.lSide[7], self.bSide[3] = self.fSide[7], self.lSide[7], self.bSide[3], self.rSide[7]
  52.  
  53. def doR(self):
  54.  
  55. 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]
  56.  
  57. self.fSide[7], self.uSide[7], self.bSide[7], self.dSide[7] = self.dSide[7], self.fSide[7], self.uSide[7], self.bSide[7]
  58. self.fSide[0], self.uSide[0], self.bSide[0], self.dSide[0] = self.dSide[0], self.fSide[0], self.uSide[0], self.bSide[0]
  59. self.fSide[1], self.uSide[1], self.bSide[1], self.dSide[1] = self.dSide[1], self.fSide[1], self.uSide[1], self.bSide[1]
  60.  
  61. def doRp(self):
  62. 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]
  63.  
  64. self.dSide[7], self.fSide[7], self.uSide[7], self.bSide[7] = self.fSide[7], self.uSide[7], self.bSide[7], self.dSide[7]
  65. self.dSide[0], self.fSide[0], self.uSide[0], self.bSide[0] = self.fSide[0], self.uSide[0], self.bSide[0], self.dSide[0]
  66. self.dSide[1], self.fSide[1], self.uSide[1], self.bSide[1] = self.fSide[1], self.uSide[1], self.bSide[1], self.dSide[1]
  67.  
  68. def doF(self):
  69. 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]
  70.  
  71. self.uSide[1], self.rSide[3], self.dSide[5], self.lSide[7] = self.lSide[7], self.uSide[1], self.rSide[3], self.dSide[5]
  72. self.uSide[2], self.rSide[4], self.dSide[6], self.lSide[0] = self.lSide[0], self.uSide[2], self.rSide[4], self.dSide[6]
  73. self.uSide[3], self.rSide[5], self.dSide[7], self.lSide[1] = self.lSide[1], self.uSide[3], self.rSide[5], self.dSide[7]
  74.  
  75. def doFp(self):
  76. 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]
  77.  
  78. self.lSide[7], self.uSide[1], self.rSide[3], self.dSide[5] = self.uSide[1], self.rSide[3], self.dSide[5], self.lSide[7]
  79. self.lSide[0], self.uSide[2], self.rSide[4], self.dSide[6] = self.uSide[2], self.rSide[4], self.dSide[6], self.lSide[0]
  80. self.lSide[1], self.uSide[3], self.rSide[5], self.dSide[7] = self.uSide[3], self.rSide[5], self.dSide[7], self.lSide[1]
  81.  
  82.  
  83.  
  84. def doAlg(self, algString):
  85. ialg = algString.replace('(', '') #get rid of unwanted
  86. ialg = ialg.replace(')', '') # or otherwise unneeded characters
  87. ialg = ialg.replace("2'", '2') # incl. whitespace, paren., 2's
  88. ialg = ialg.replace(' ', ' ')
  89. parts = ialg.split(' ') #Divide the alg up into individual moves
  90.  
  91. for part in parts:
  92. if part == 'U': self.doU()
  93. elif part == 'U2': self.doU(); self.doU()
  94. elif part == "U'": self.doUp()
  95.  
  96. elif part == 'F': self.doF()
  97. elif part == 'F2': self.doF(); self.doF()
  98. elif part == "F'": self.doFp()
  99.  
  100. elif part == 'R': self.doR()
  101. elif part == 'R2': self.doR(); self.doR()
  102. elif part == "R'": self.doRp()
  103.  
  104. def checkSolved(self):
  105. 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]:
  106. if self.fSide[5] == self.fSide[6] == self.fSide[7]:
  107. if self.lSide[5] == self.lSide[6] == self.lSide[7]:
  108. if self.rSide[5] == self.rSide[6] == self.rSide[7]:
  109. if self.bSide[3] == self.bSide[2] == self.bSide[1]:
  110. return True
  111. return False
  112. ##################################################
  113. def tryAll(a, b, c, this):
  114. aCube = MyCube(); aCube.doAlg(this)
  115. if aCube.checkSolved():
  116. #print '1',
  117. return True
  118.  
  119. for w in range(4):
  120. aCube.doU(); aCub = aCube
  121.  
  122. for x in [a, b, c]:
  123. tCube = aCub
  124. tCube.doAlg(x)
  125. if tCube.checkSolved():
  126. #print '2',
  127. return True
  128.  
  129. for y in range(4):
  130. tCube.doU(); tCub = tCube
  131.  
  132. for z in [a, b, c]:
  133. tCu = tCub; tCu.doAlg(z)
  134. if tCube.checkSolved():
  135. #print '3',
  136. return True
  137. return False
  138.  
  139.  
  140. def tryCombo(a, b, c, listNow):
  141. for alg in range(0, len(algs)):
  142. if listNow[alg] == False:
  143. if tryAll(a, b, c, algs[alg]):
  144. listNow[alg] = True; continue
  145.  
  146. else: return listNow
  147.  
  148. return listNow
  149. ##################################################
  150. ## Memo 3 algs? ##
  151.  
  152. listTimes = []
  153. megaList = []
  154. highest = 0
  155. count = 0; counta = 0
  156. for l1 in range(7,len(algs)):
  157. print "L1: ", l1, counta
  158. counta = 0
  159. for l2 in range(l1+1,len(algs)):
  160. for l3 in range(l2+1,len(algs)):
  161.  
  162. count+=1; counta+=1
  163. algsDone = [False]*len(algs)
  164. s = time.time()
  165. algsDone = tryCombo(algs[l1], algs[l2], algs[l3], algsDone)
  166. listTimes.append(time.time()-s)
  167. if sum(algsDone) == len(algs):
  168. print "\t\tAlgs used: ", l1, l2, l3
  169. megaList.append([l1, l2, l3])
  170. #print "\t\tCases solved: " + str(sum(algsDone)) + " out of " + str(len(algs))
  171. #print "\t\t", algsDone; print
  172. highest = sum(algsDone)
  173. print '\n\n'
  174.  
  175. print count
  176. print; print time.time()-start; print
  177. k = 0; l = 0
  178. for t in listTimes:
  179. k+=1; l+=t
  180. print l/k, l
  181. print megaList
  182.  
Time limit exceeded #stdin #stdout -1s 6940KB
stdin
Standard input is empty
stdout

Standard output is empty