-
Notifications
You must be signed in to change notification settings - Fork 0
/
beginner
245 lines (216 loc) · 5.53 KB
/
beginner
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#
# Top cross
#
func handle_front_bottom(): boolean
let moving: color = front[2, 1]
if moving == left[1, 1] then
D'L2
else-if moving == right[1, 1] then
D R2
else-if moving == back[1, 1] then
D2 B2
else
F2
return false
end
return true
end
let over: boolean = false
while not(over) do
orient top: {---/-x-/---}, right: {---/x--/---}, keeping: top then
F
if handle_front_bottom() then F' end
else-orient top: {---/-x-/---}, left: {---/--x/---}, keeping: top then
F'
if handle_front_bottom() then F end
else-orient top: {---/-x-/---}, bottom: {-x-/---/---}, keeping: top then
handle_front_bottom()
else-orient top: {---/-x-/---}, front: {---/---/-x-}, keeping: top then
if bottom[0, 1] == right[1, 1] then
F'RF
else-if bottom[0, 1] == left[1, 1] then
FL'F'
else-if bottom[0, 1] == back[1, 1] then
DR'BR
else
DRF'R'
end
else-orient top: {---/-x-/-y-}, keeping: top then
FF
else-orient front: {-x-/-y-/---}, keeping: top then
FF
else
over = true
end
end
#
# Top layer
#
over = false
while not(over) do
orient top: {---/-x-/---}, right: {---/---/x--}, keeping: top then
suspend_rotations()
while front[1, 1] != front[2, 2] do
DY
end
resume_rotations()
DFD'F'
else-orient top: {---/-x-/---}, left: {---/---/--x}, keeping: top then
suspend_rotations()
while front[1, 1] != front[2, 0] do
D'Y'
end
resume_rotations()
D'F'DF
else-orient top: {---/-x-/---}, bottom: {--x/---/---}, keeping: top then
suspend_rotations()
while front[2, 2] != front[1, 1] do
DY
end
resume_rotations()
R'DR
else-orient top: {---/-x-/---}, front: {--x/---/---}, keeping: top then
FDF'
else-orient top: {---/-x-/---}, right: {x--/---/---}, keeping: top then
R'D'R
else-orient top: {---/-x-/--x}, front: {--y/-z-/---}, keeping: top then
R'D'R
else
over = true
end
end
#
# Middle section
#
func push_to_right() D'R'DRDFD'F' end
func push_to_left() DLD'L'D'F'DF end
over = false
while not(over) do
orient bottom: {-x-/-y-/---}, front: {---/---/-z-}, keeping: top then
suspend_rotations()
while front[2, 1] != front[1, 1] do
DY
end
resume_rotations()
if bottom[0, 1] == right[1, 1] then
push_to_right()
else
push_to_left()
end
else
let found_side: boolean = false
let turns: int = 0
suspend_rotations()
while turns < 4 and not(found_side) do
if ((front[1, 2] != front[1, 1] or right[1, 0] != right[1, 1]) \
and front[1, 2] != bottom[1, 1] and left[1, 0] != bottom[1, 1]) then
found_side = true
push_to_right()
else
Y
turns = turns + 1
end
end
resume_rotations()
over = not(found_side)
end
end
X2
#
# Bottom cross
#
func run_bottom_cross() FRUR'U'F' end
orient top: {---/xx-/---}, keeping: top then noop else
run_bottom_cross()
orient top: {---/xx-/---}, keeping: top then noop end
end
if top[1, 0] != top[1, 2] then
orient top: {-x-/xx-/---}, keeping: top then noop end
run_bottom_cross()
end
if top[0, 1] != top[1, 1] then
run_bottom_cross()
end
#
# Correct bottom cross
#
func count_top_correct(): int
let count: int = 0
suspend_rotations()
repeat 4 times
if front[0, 1] == front[1, 1] then
count = count + 1
end
Y
end
resume_rotations()
return count
end
let correct_count: int = 0
while correct_count < 2 do
correct_count = count_top_correct()
if correct_count < 2 then
U
end
end
if correct_count != 4 then
orient left: {-a-/-a-/---}, right: {-b-/-b-/---}, keeping: top then
RUR'URU2R'
while count_top_correct() < 2 do
U
end
end
orient right: {-a-/-a-/---}, back: {-b-/-b-/---}, keeping: top then
RUR'URU2R'U
end
end
#
# Correct positions on top side
#
over = false
while not(over) do
let i: int = 0
let corner_found: boolean = false
while not(corner_found) and i < 4 do
let corner_expected: set of color = set_of(left[1, 1], top[1, 1], front[1, 1])
let corner_actual: set of color = set_of(front[0, 0], top[2, 0], left[0, 2])
corner_found = corner_expected == corner_actual
if not (corner_found) then
Y
end
i = i + 1
end
if not(corner_found) then
URU'L'UR'U'L
else
let right_corner: set of color = set_of(right[0, 0], front[0, 2], top[2, 2])
if right_corner == set_of(right[1, 1], front[1, 1], top[1, 1]) then
over = true
else-if right_corner == set_of(left[1, 1], back[1, 1], top[1, 1]) then
U'L'URU'LUR'
else
Y'
URU'L'UR'U'L
end
end
end
#
# Correct orientation of the top side
#
orient top: {---/-x-/--y}, keeping: top then
over = false
while not(over) do
while top[1, 1] != top[2, 2] do
R'D'RD
end
let turns: int = 0
while top[1, 1] == top[2, 2] and turns < 4 do
U
turns = turns + 1
end
over = turns == 4
end
while front[0, 1] != front[1, 1] do
U
end
end