fork download
  1. import time; start = time.time()
  2.  
  3. algs = ["",
  4. "R' U R' U' R' U' R' U R U R2",
  5. "R U' R U R U R U' R' U' R2",
  6. "R2 U2 R U2 R2 U2 R2 U2 R U2 R2",
  7. "R2 U R2 U' R2 F2 R2 U' F2 U R2 F2",
  8. "R U' R F2 R' U R' U' R2 F2 R2",
  9. "R2 F2 R2 U R U' R F2 R' U R'",
  10. "R U R' U R' U' R F' R U R' U' R' F R2 U' R2 U R",
  11. "F' U2 R' U F U' F' U' R U' F",
  12. "R U R' F' R U R' U' R' F R2 U' R'",
  13. "R' U2 R U2 R' F R U R' U' R' F' R2",
  14. "F' R' U' R F' R' U F' U' F' U F R F2",
  15. "F2 R2 U' R' U' R F2 R' U R F2 U R2 F2",
  16. "F2 R2 U' F2 R' U' R F2 R' U R U R2 F2",
  17. "R' U' R2 U' R2 U' R U2 R2 F U R' U' R F' R",
  18. "R' F R' U R U' F' R2 U2 R' U R2 U R2 U R",
  19. "F' R U R' U' R' F R2 F U' R' U' R U F' R'",
  20. "R' U R' F R F' R U' R' F' U F R U R' U' R",
  21. "R U R' U' R' F R2 U' R' U' R U R' F'",
  22. "F R U' R' U' R U R' F' R U R' U' R' F R F'",
  23. "F' U2 F' U' R' F' R2 U' R' U R' F R U' F",
  24. "R U' R U F R F2 U F U' F R' F' R'"]
  25.  
  26. ##################################################
  27. class MyCube:
  28. """A virtual 3x3x3 matrix"""
  29. def __init__(self):
  30. self.uSide = ['U0', 'U1', 'U2', 'U3', 'U4', 'U5', 'U6', 'U7'] #URF, UF, etc
  31. self.fSide = ['F0', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7'] #FRD, FD, etc
  32. self.lSide = ['L0', 'L1', 'L2', 'L3', 'L4', 'L5', 'L6', 'L7'] #LFD, LD, etc
  33. self.bSide = ['B0', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7'] #BRD, BD, etc
  34. self.rSide = ['R0', 'R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7'] #RBD, RD, etc
  35. self.dSide = ['D0', 'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7'] #DBR, DR, etc
  36.  
  37. def doU(self):
  38. 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]
  39.  
  40. self.fSide[5], self.lSide[5], self.bSide[5], self.rSide[5] = self.rSide[5], self.fSide[5], self.lSide[5], self.bSide[5]
  41. self.fSide[6], self.lSide[6], self.bSide[6], self.rSide[6] = self.rSide[6], self.fSide[6], self.lSide[6], self.bSide[6]
  42. self.fSide[7], self.lSide[7], self.bSide[7], self.rSide[7] = self.rSide[7], self.fSide[7], self.lSide[7], self.bSide[7]
  43.  
  44. def doR(self):
  45. 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]
  46.  
  47. self.fSide[7], self.uSide[7], self.bSide[3], self.dSide[7] = self.dSide[7], self.fSide[7], self.uSide[7], self.bSide[3]
  48. self.fSide[0], self.uSide[0], self.bSide[4], self.dSide[0] = self.dSide[0], self.fSide[0], self.uSide[0], self.bSide[4]
  49. self.fSide[1], self.uSide[1], self.bSide[5], self.dSide[1] = self.dSide[1], self.fSide[1], self.uSide[1], self.bSide[5]
  50.  
  51. def doF(self):
  52. 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]
  53.  
  54. self.uSide[1], self.rSide[3], self.dSide[5], self.lSide[7] = self.lSide[7], self.uSide[1], self.rSide[3], self.dSide[5]
  55. self.uSide[2], self.rSide[4], self.dSide[6], self.lSide[0] = self.lSide[0], self.uSide[2], self.rSide[4], self.dSide[6]
  56. self.uSide[3], self.rSide[5], self.dSide[7], self.lSide[1] = self.lSide[1], self.uSide[3], self.rSide[5], self.dSide[7]
  57.  
  58. def returnCrazy(self):
  59. l = []
  60. l.append(self.uSide)
  61. l.append(self.fSide)
  62. l.append(self.lSide)
  63. l.append(self.bSide)
  64. l.append(self.rSide)
  65. return l#; print l
  66.  
  67. def doAlg(self, algString):
  68. ialg = algString.replace('(', '') #get rid of unwanted
  69. ialg = ialg.replace(')', '') # or otherwise unneeded characters
  70. ialg = ialg.replace("2'", '2') # incl. whitespace, paren., 2's
  71. ialg = ialg.replace(' ', ' ')
  72. parts = ialg.split(' ') #Divide the alg up into individual moves
  73.  
  74. #parts.reverse()
  75.  
  76. for part in parts:
  77. if part == 'U': self.doU()
  78. elif part == 'U2': self.doU(); self.doU()
  79. elif part == "U'": self.doU(); self.doU(); self.doU()
  80.  
  81. elif part == 'F': self.doF()
  82. elif part == 'F2': self.doF(); self.doF()
  83. elif part == "F'": self.doF(); self.doF(); self.doF()
  84.  
  85. elif part == 'R': self.doR()
  86. elif part == 'R2': self.doR(); self.doR()
  87. elif part == "R'": self.doR(); self.doR(); self.doR()
  88.  
  89. ############### Writing the functions: start ###############
  90. f = open('C:/Users/skorick/Desktop/all/test/test.txt', 'w')
  91. k = "#"*50 + '\n'
  92.  
  93. f.write(k)
  94. f.write(' def doCrazy(self, a):\t#code generated with writing.py\n')
  95.  
  96. f.write(' temp = self\n\n')
  97. f.write(' if a == "":\t#default (finished) case:\n')
  98.  
  99. f.write(' pass\n\n')
  100.  
  101.  
  102. for x in range(1,len(algs)): #write a conditional procedure for each of these
  103.  
  104. f.write(' elif a == "' + algs[x] + '":\t#' + str(x) + '\n')
  105. new = MyCube(); new.doAlg(algs[x])
  106.  
  107. a = new.returnCrazy(); print a, '\n\n'
  108.  
  109. f.write(' ')
  110. ######################################################################
  111. ############################ U: ############################
  112. for x in range(0,8):#uSide
  113. f.write('temp.' + a[0][x][0].lower() + 'Side[' + str(a[0][x][1]) + '] = self.uSide[' + str(x))
  114.  
  115. f.write(']; ') if x<7 else f.write(']')
  116.  
  117. ############################ F: ############################
  118. f.write('\n\n ')
  119. for yf in range(5,8):
  120. f.write('temp.' + a[1][yf][0].lower() + 'Side[' + str(a[1][yf][1]) + '] = self.fSide[' + str(yf))
  121.  
  122. f.write(']; ') if yf<7 else f.write(']')
  123. ############################ L: ############################
  124. f.write('\n ')
  125. for yl in range(5,8):
  126. f.write('temp.' + a[2][yl][0].lower() + 'Side[' + str(a[2][yl][1]) + '] = self.lSide[' + str(yl))
  127.  
  128. f.write(']; ') if yl<7 else f.write(']')
  129. ############################ B: ############################
  130. f.write('\n ')
  131. for yb in range(5,8):
  132. f.write('temp.' + a[3][yb][0].lower() + 'Side[' + str(a[3][yb][1]) + '] = self.bSide[' + str(yb))
  133.  
  134. f.write(']; ') if yb<7 else f.write(']')
  135. ############################ R: ############################
  136. f.write('\n ')
  137. for yr in range(5,8):
  138. f.write('temp.' + a[4][yr][0].lower() + 'Side[' + str(a[4][yr][1]) + '] = self.rSide[' + str(yr))
  139.  
  140. f.write(']; ') if yr<7 else f.write(']')
  141. ############################ finish ############################
  142. ######################################################################
  143. f.write('\n self.resetSelf([temp.uSide, temp.fSide, temp.lSide, temp.bSide, temp.rSide, temp.dSide])\n\n')
  144.  
  145. f.write(' else: print "BAD"\n')
  146. f.write(k)
  147. f.close()
  148. ############### Writing the functions: end ###############
  149.  
  150. print time.time()-start
  151.  
Success #stdin #stdout 0.02s 6936KB
stdin
Standard input is empty
stdout

Standard output is empty