# Cube.py

May 25th, 2014
412
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import copy
2. perfect_cube={'U':['W']*9,'F':['R']*9,'D':['Y']*9,'B':['O']*9,'L':['G']*9,'R':['B']*9}
3. def move(face,cube,row,cycling,rev=0):
4.      cubenew = copy.deepcopy(cube)
5.      if rev==1:
6.     cycling = [i for i in reversed(cycling)]
7.      for i in row:
8.              cubenew[cycling[0]][i]=cube[cycling[1]][i]
9.              cubenew[cycling[1]][i]=cube[cycling[2]][i]
10.              cubenew[cycling[2]][i]=cube[cycling[3]][i]
11.              cubenew[cycling[3]][i]=cube[cycling[0]][i]
12.      if not rev:
13.     for i,j,k,l in zip([0,1,2],[2,5,8],[8,7,6],[6,3,0]):
14.          cubenew[face][i]=cube[face][j]
15.              cubenew[face][j]=cube[face][k]
16.              cubenew[face][k]=cube[face][l]
17.              cubenew[face][l]=cube[face][i]
18.      else:
19.     for i,j,k,l in zip([0,1,2],[6,3,0],[8,7,6],[2,5,8]):
20.          cubenew[face][i]=cube[face][j]
21.              cubenew[face][j]=cube[face][k]
22.              cubenew[face][k]=cube[face][l]
23.              cubenew[face][l]=cube[face][i]
24.      return cubenew
25.
26. def fbmove(face,cube,row,cycling,rev=0):
27.      cubenew = copy.deepcopy(cube)
28.      for i,j,k,l in row:
29.              cubenew[cycling[0]][i]=cube[cycling[1]][j]
30.              cubenew[cycling[1]][j]=cube[cycling[2]][k]
31.              cubenew[cycling[2]][k]=cube[cycling[3]][l]
32.              cubenew[cycling[3]][l]=cube[cycling[0]][i]
33.      if not rev:
34.     for i,j,k,l in zip([0,1,2],[2,5,8],[8,7,6],[6,3,0]):
35.          cubenew[face][i]=cube[face][j]
36.              cubenew[face][j]=cube[face][k]
37.              cubenew[face][k]=cube[face][l]
38.              cubenew[face][l]=cube[face][i]
39.      else:
40.     for i,j,k,l in zip([0,1,2],[6,3,0],[8,7,6],[2,5,8]):
41.          cubenew[face][i]=cube[face][j]
42.              cubenew[face][j]=cube[face][k]
43.              cubenew[face][k]=cube[face][l]
44.              cubenew[face][l]=cube[face][i]
45.      return cubenew
46.
47. R = lambda c: move('R',c,[6,7,8],['U','F','D','B'])
48. Rdash = lambda c: move('R',c,[8,7,6],['U','F','D','B'],1)
49. L = lambda c: move('L',c,[0,1,2],['B','D','F','U'])
50. Ldash = lambda c: move('L',c,[2,1,0],['B','D','F','U'],1)
51. U = lambda c: fbmove('U',c,zip([0,3,6],[0,3,6],[8,5,2],[0,3,6]),['F','R','B','L'])
52. Udash = lambda c: fbmove('U',c,zip([0,3,6],[8,5,2],[0,3,6],[0,3,6]),['L','B','R','F'],1)
53. D = lambda c: fbmove('D',c,zip([8,5,2],[0,3,6],[8,5,2],[8,5,2]),['L','B','R','F'])
54. Ddash = lambda c: fbmove('D',c,zip([8,5,2],[8,5,2],[0,3,6],[8,5,2]),['F','R','B','L'],1)
55. F = lambda c: fbmove('F',c,zip([2,5,8],[8,7,6],[6,3,0],[0,1,2]),['U','L','D','R'])
56. Fdash = lambda c: fbmove('F',c,zip([0,1,2],[6,3,0],[8,7,6],[2,5,8]),['R','D','L','U'],1)
57. B = lambda c: fbmove('B',c,zip([6,7,8],[8,5,2],[2,1,0],[0,3,6]),['R','D','L','U'])
58. Bdash = lambda c: fbmove('B',c,zip([0,3,6],[2,1,0],[8,5,2],[6,7,8]),['U','L','D','R'],1)
59.
60. def countt(s):
61.      c = copy.deepcopy(perfect_cube)
62.      i = 1
63.      while True:
64.              for f in s:
65.                      c = f(c)
66.              if c == perfect_cube:
67.                      break
68.              i += 1
69.      return i
RAW Paste Data