Advertisement
Jakube

ComputeOrder

Apr 4th, 2020
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. def apply_alg(state, alg):
  2.     for move in alg.split():
  3.         perm = "FLBR FRBL FDBU FUBD URDL ULDR".split()['UDLRFB'.index(move[0])]
  4.         n = 2 + "2'".find(move[-1])
  5.         table = str.maketrans(perm, perm[n:] + perm[:n])
  6.         state = [p.translate(table) if move[0] in p else p for p in state]
  7.     return state
  8.  
  9. def compute_order(alg):
  10.     start_state = "UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR".split()
  11.  
  12.     state = apply_alg(start_state, alg)
  13.     order = 1
  14.     while state != start_state:
  15.         state = apply_alg(state, alg)
  16.         order += 1
  17.     return order
  18.  
  19. if __name__ == "__main__":
  20.     alg = "R U2 D' B D'"
  21.     print(f"Order of {alg} is {compute_order(alg)}.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement