Last active
August 29, 2015 14:03
-
-
Save pochmann/a70e314bbeb954b13ef5 to your computer and use it in GitHub Desktop.
Check whether two 3x3x3 algorithms are equivalent by simulating their effects and comparing the results. I love this way to simulate these puzzles, no complicated data structures needed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sim(alg): | |
state = "UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR".split() | |
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 | |
print(sim("D L2 B2 L2 R2 F2 R2 U2 R2 D' U' R' B F L' D R2") == sim("U R B F L D R2")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment