Created
October 22, 2013 19:46
-
-
Save larsr/7106946 to your computer and use it in GitHub Desktop.
"triangle rubik"-cube movements as list permutations.
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
moves = """ | |
1 14 76 | |
2 15 77 | |
3 16 78 | |
4 17 74 | |
5 18 75 | |
6 19 71 | |
7 20 72 | |
8 21 73 | |
9 22 69 | |
10 23 70 | |
68 24 66 | |
12 25 67 | |
13 26 68 | |
29 27 16 | |
15 28 21 | |
16 29 26 | |
31 30 18 | |
18 31 23 | |
28 32 15 | |
33 33 20 | |
21 34 25 | |
30 35 17 | |
35 36 22 | |
27 37 14 | |
32 38 19 | |
37 39 24 | |
55 40 53 | |
60 41 54 | |
65 42 55 | |
57 43 56 | |
62 44 57 | |
54 45 58 | |
59 46 59 | |
34 47 60 | |
56 48 61 | |
36 49 62 | |
53 50 63 | |
38 51 64 | |
39 52 65 | |
11 1 50 | |
41 2 45 | |
42 3 40 | |
43 4 48 | |
44 5 43 | |
45 6 51 | |
46 7 46 | |
47 8 41 | |
48 9 49 | |
49 10 44 | |
50 11 52 | |
51 12 47 | |
52 13 42 | |
26 55 13 | |
25 60 12 | |
24 65 11 | |
23 57 10 | |
22 62 9 | |
58 54 8 | |
20 59 7 | |
19 64 6 | |
61 56 5 | |
17 61 4 | |
63 53 3 | |
64 58 2 | |
14 63 1 | |
66 68 29 | |
67 73 28 | |
40 78 27 | |
69 70 31 | |
70 75 30 | |
71 67 34 | |
72 72 33 | |
73 77 32 | |
74 69 36 | |
75 74 35 | |
76 66 39 | |
77 71 38 | |
78 76 37 | |
""" | |
moves = [[int(y) for y in x.split()] for x in moves.strip().split('\n')] | |
def transpose(x): | |
rows = len(x) | |
cols = len(x[0]) | |
return [ [x[r][c] for r in range(rows)] for c in range(cols)] | |
[A, B, C] = transpose (moves) | |
def do(pos,move): | |
return [move[pos[i]-1] for i in range(len(pos))] | |
I = range(1,79) | |
assert(do(do(do(I,A),A),A)==I) | |
assert(do(do(do(do(I,B),B),B),B)==I)) | |
assert(do(do(do(do(I,C),C),C),C)==I) | |
def mm(pos,*moves): | |
for m in moves: | |
pos = do(pos, m) | |
return pos | |
# FWD == B == roll forward | |
FWD = B | |
# C == rotate clockwise (w.r.t top layer) | |
CLCK = C | |
# BWD == roll backward | |
BWD = mm(I,FWD,FWD,FWD) | |
# CCLCK = rotate counter-clockwise | |
CCLCK = mm(I,CLCK,CLCK,CLCK) | |
# LEFT == roll to the left | |
LEFT = mm(I,CLCK,BWD,CCLCK) | |
# RIGHT == roll to the right | |
RIGHT = mm(I,CLCK,FWD,CCLCK) | |
assert(mm(I,A,A,A)==I) | |
assert(mm(I,FWD,FWD,FWD,FWD)==I) | |
assert(mm(I,CLCK,CLCK,CLCK,CLCK)==I) | |
assert(mm(I,CCLCK,CCLCK,CCLCK,CCLCK)==I) | |
assert(mm(I,BWD,BWD,BWD,BWD)==I) | |
assert(mm(I,LEFT,LEFT,LEFT)==RIGHT) | |
# rotate corners of top layer | |
# so that top surface moves towards player i.e. end up on front side | |
# 4-3 | |
# | | top layer corners seen from above | |
# 1-2 | |
R1 = A | |
R2 = mm(I,CLCK, R1, R1, CCLCK) | |
R3 = mm(I,CLCK, R2, CCLCK) | |
R4 = mm(I,CCLCK, R1, CLCK) | |
R2x = mm(I,LEFT,R1,R1,RIGHT) | |
R3x = mm(I, FWD, R2, BWD) | |
R4x = mm(I, FWD, R1, BWD) | |
assert (R2 == R2x) | |
assert (R3 == R3x) | |
assert (R4 == R4x) | |
# rotate corners of bottom layer | |
# so that bottom surface moves towards player, i.e. end up on front side | |
# 8-7 | |
# | | bottom layer corners seen from above "through" the cube | |
# 5-6 | |
R5 = mm(I,BWD, R1, R1, FWD) | |
R6 = mm(I,BWD, R2, R2, FWD) | |
R7 = mm(I,BWD, R6, FWD) | |
R8 = mm(I,BWD, R5, FWD) | |
def period(m): | |
n = 1 | |
x = I | |
x = mm(x,m) | |
while x != I: | |
n += 1 | |
x = mm(x,m) | |
return n | |
X = mm(I,R1,R2,R3,R4) | |
X = mm(I,R1,R2,R2,R3,R3,R4) | |
print period(X) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment