Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def apply_alg(state, alg):
- for move in alg.split():
- perm = "FLBR FRBL FDBU FUBD URDL ULDR".split()['UDLRFB'.index(move[0])]
- n = 2 + "2'".find(move[-1])
- table = str.maketrans(perm, perm[n:] + perm[:n])
- state = [p.translate(table) if move[0] in p else p for p in state]
- return state
- def compute_order(alg):
- start_state = "UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR".split()
- state = apply_alg(start_state, alg)
- order = 1
- while state != start_state:
- state = apply_alg(state, alg)
- order += 1
- return order
- if __name__ == "__main__":
- alg = "R U2 D' B D'"
- print(f"Order of {alg} is {compute_order(alg)}.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement