Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import copy
- perfect_cube={'U':['W']*9,'F':['R']*9,'D':['Y']*9,'B':['O']*9,'L':['G']*9,'R':['B']*9}
- def move(face,cube,row,cycling,rev=0):
- cubenew = copy.deepcopy(cube)
- if rev==1:
- cycling = [i for i in reversed(cycling)]
- for i in row:
- cubenew[cycling[0]][i]=cube[cycling[1]][i]
- cubenew[cycling[1]][i]=cube[cycling[2]][i]
- cubenew[cycling[2]][i]=cube[cycling[3]][i]
- cubenew[cycling[3]][i]=cube[cycling[0]][i]
- if not rev:
- for i,j,k,l in zip([0,1,2],[2,5,8],[8,7,6],[6,3,0]):
- cubenew[face][i]=cube[face][j]
- cubenew[face][j]=cube[face][k]
- cubenew[face][k]=cube[face][l]
- cubenew[face][l]=cube[face][i]
- else:
- for i,j,k,l in zip([0,1,2],[6,3,0],[8,7,6],[2,5,8]):
- cubenew[face][i]=cube[face][j]
- cubenew[face][j]=cube[face][k]
- cubenew[face][k]=cube[face][l]
- cubenew[face][l]=cube[face][i]
- return cubenew
- def fbmove(face,cube,row,cycling,rev=0):
- cubenew = copy.deepcopy(cube)
- for i,j,k,l in row:
- cubenew[cycling[0]][i]=cube[cycling[1]][j]
- cubenew[cycling[1]][j]=cube[cycling[2]][k]
- cubenew[cycling[2]][k]=cube[cycling[3]][l]
- cubenew[cycling[3]][l]=cube[cycling[0]][i]
- if not rev:
- for i,j,k,l in zip([0,1,2],[2,5,8],[8,7,6],[6,3,0]):
- cubenew[face][i]=cube[face][j]
- cubenew[face][j]=cube[face][k]
- cubenew[face][k]=cube[face][l]
- cubenew[face][l]=cube[face][i]
- else:
- for i,j,k,l in zip([0,1,2],[6,3,0],[8,7,6],[2,5,8]):
- cubenew[face][i]=cube[face][j]
- cubenew[face][j]=cube[face][k]
- cubenew[face][k]=cube[face][l]
- cubenew[face][l]=cube[face][i]
- return cubenew
- R = lambda c: move('R',c,[6,7,8],['U','F','D','B'])
- Rdash = lambda c: move('R',c,[8,7,6],['U','F','D','B'],1)
- L = lambda c: move('L',c,[0,1,2],['B','D','F','U'])
- Ldash = lambda c: move('L',c,[2,1,0],['B','D','F','U'],1)
- U = lambda c: fbmove('U',c,zip([0,3,6],[0,3,6],[8,5,2],[0,3,6]),['F','R','B','L'])
- Udash = lambda c: fbmove('U',c,zip([0,3,6],[8,5,2],[0,3,6],[0,3,6]),['L','B','R','F'],1)
- D = lambda c: fbmove('D',c,zip([8,5,2],[0,3,6],[8,5,2],[8,5,2]),['L','B','R','F'])
- Ddash = lambda c: fbmove('D',c,zip([8,5,2],[8,5,2],[0,3,6],[8,5,2]),['F','R','B','L'],1)
- F = lambda c: fbmove('F',c,zip([2,5,8],[8,7,6],[6,3,0],[0,1,2]),['U','L','D','R'])
- Fdash = lambda c: fbmove('F',c,zip([0,1,2],[6,3,0],[8,7,6],[2,5,8]),['R','D','L','U'],1)
- B = lambda c: fbmove('B',c,zip([6,7,8],[8,5,2],[2,1,0],[0,3,6]),['R','D','L','U'])
- Bdash = lambda c: fbmove('B',c,zip([0,3,6],[2,1,0],[8,5,2],[6,7,8]),['U','L','D','R'],1)
- def countt(s):
- c = copy.deepcopy(perfect_cube)
- i = 1
- while True:
- for f in s:
- c = f(c)
- if c == perfect_cube:
- break
- i += 1
- return i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement