1 /*  twist.c  version 1.1  may 6, 2002  */
2 
3 
4 #include  <stdio.h>
5 #include  <stdlib.h>
6 #include  <string.h>
7 
8 
9 typedef struct cube
10         {
11         int             edges[24];
12         int             corners[24];
13         }
14         Cube;
15 
16 
17 #define  MAX_INPUT_LENGTH                 1024
18 
19 
20 /*  number the corner cubies  */
21 
22 #define  CORNER_UFR                          0
23 #define  CORNER_URB                          1
24 #define  CORNER_UBL                          2
25 #define  CORNER_ULF                          3
26 #define  CORNER_DRF                          4
27 #define  CORNER_DFL                          5
28 #define  CORNER_DLB                          6
29 #define  CORNER_DBR                          7
30 
31 #define  CORNER_FRU                          8
32 #define  CORNER_RBU                          9
33 #define  CORNER_BLU                         10
34 #define  CORNER_LFU                         11
35 #define  CORNER_RFD                         12
36 #define  CORNER_FLD                         13
37 #define  CORNER_LBD                         14
38 #define  CORNER_BRD                         15
39 
40 #define  CORNER_RUF                         16
41 #define  CORNER_BUR                         17
42 #define  CORNER_LUB                         18
43 #define  CORNER_FUL                         19
44 #define  CORNER_FDR                         20
45 #define  CORNER_LDF                         21
46 #define  CORNER_BDL                         22
47 #define  CORNER_RDB                         23
48 
49 
50 /*  number the edge cubies  */
51 
52 #define  EDGE_UF                             0
53 #define  EDGE_UR                             1
54 #define  EDGE_UB                             2
55 #define  EDGE_UL                             3
56 #define  EDGE_DF                             4
57 #define  EDGE_DR                             5
58 #define  EDGE_DB                             6
59 #define  EDGE_DL                             7
60 #define  EDGE_FR                             8
61 #define  EDGE_FL                             9
62 #define  EDGE_BR                            10
63 #define  EDGE_BL                            11
64 
65 #define  EDGE_FU                            12
66 #define  EDGE_RU                            13
67 #define  EDGE_BU                            14
68 #define  EDGE_LU                            15
69 #define  EDGE_FD                            16
70 #define  EDGE_RD                            17
71 #define  EDGE_BD                            18
72 #define  EDGE_LD                            19
73 #define  EDGE_RF                            20
74 #define  EDGE_LF                            21
75 #define  EDGE_RB                            22
76 #define  EDGE_LB                            23
77 
78 
79 static char            *edge_cubie_str[] = {"UF", "UR", "UB", "UL",
80                                             "DF", "DR", "DB", "DL",
81                                             "FR", "FL", "BR", "BL",
82                                             "FU", "RU", "BU", "LU",
83                                             "FD", "RD", "BD", "LD",
84                                             "RF", "LF", "RB", "LB"};
85 
86 static char            *corner_cubie_str[] = {"UFR", "URB", "UBL", "ULF",
87                                               "DRF", "DFL", "DLB", "DBR",
88                                               "FRU", "RBU", "BLU", "LFU",
89                                               "RFD", "FLD", "LBD", "BRD",
90                                               "RUF", "BUR", "LUB", "FUL",
91                                               "FDR", "LDF", "BDL", "RDB"};
92 
93 
94 /* ========================================================================= */
perm_n_init(int nn,int array_out[])95    void  perm_n_init(int  nn, int  array_out[])
96 /* ------------------------------------------------------------------------- */
97 
98 {
99 int                     ii;
100 
101 
102 for (ii = 0; ii < nn; ii++)
103     array_out[ii] = ii;
104 
105 return;
106 }
107 
108 
109 /* ========================================================================= */
perm_n_inverse(int nn,int perm_in[],int perm_out[])110    void  perm_n_inverse(int  nn, int  perm_in[], int  perm_out[])
111 /* ------------------------------------------------------------------------- */
112 
113 {
114 int                     ii;
115 
116 
117 for (ii = 0; ii < nn; ii++)
118     perm_out[perm_in[ii]] = ii;
119 
120 return;
121 }
122 
123 
124 /* ========================================================================= */
two_cycle(int arr[],int ind0,int ind1)125    void  two_cycle(int  arr[], int  ind0, int  ind1)
126 /* ------------------------------------------------------------------------- */
127 
128 {
129 int                     temp;
130 
131 
132 temp = arr[ind0];
133 arr[ind0] = arr[ind1];
134 arr[ind1] = temp;
135 
136 return;
137 }
138 
139 
140 /* ========================================================================= */
four_cycle(int arr[],int ind0,int ind1,int ind2,int ind3)141    void  four_cycle(int  arr[], int  ind0, int  ind1, int  ind2, int  ind3)
142 /* ------------------------------------------------------------------------- */
143 
144 {
145 int                     temp;
146 
147 
148 temp = arr[ind0];
149 arr[ind0] = arr[ind1];
150 arr[ind1] = arr[ind2];
151 arr[ind2] = arr[ind3];
152 arr[ind3] = temp;
153 
154 return;
155 }
156 
157 
158 /* ========================================================================= */
cube_init(Cube * p_cube)159    void  cube_init(Cube  *p_cube)
160 /* ------------------------------------------------------------------------- */
161 
162 {
163 perm_n_init(24, p_cube->edges);
164 perm_n_init(24, p_cube->corners);
165 
166 return;
167 }
168 
169 
170 /* ========================================================================= */
cube_inverse(Cube * p_cube_in,Cube * p_cube_out)171    void  cube_inverse(Cube  *p_cube_in, Cube  *p_cube_out)
172 /* ------------------------------------------------------------------------- */
173 
174 {
175 perm_n_inverse(24, p_cube_in->edges, p_cube_out->edges);
176 perm_n_inverse(24, p_cube_in->corners, p_cube_out->corners);
177 
178 return;
179 }
180 
181 
182 /* ========================================================================= */
print_cube(Cube * p_cube)183    void  print_cube(Cube  *p_cube)
184 /* ------------------------------------------------------------------------- */
185 
186 {
187 printf("%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n",
188        edge_cubie_str[p_cube->edges[0]], edge_cubie_str[p_cube->edges[1]],
189        edge_cubie_str[p_cube->edges[2]], edge_cubie_str[p_cube->edges[3]],
190        edge_cubie_str[p_cube->edges[4]], edge_cubie_str[p_cube->edges[5]],
191        edge_cubie_str[p_cube->edges[6]], edge_cubie_str[p_cube->edges[7]],
192        edge_cubie_str[p_cube->edges[8]], edge_cubie_str[p_cube->edges[9]],
193        edge_cubie_str[p_cube->edges[10]], edge_cubie_str[p_cube->edges[11]],
194    corner_cubie_str[p_cube->corners[0]], corner_cubie_str[p_cube->corners[1]],
195    corner_cubie_str[p_cube->corners[2]], corner_cubie_str[p_cube->corners[3]],
196    corner_cubie_str[p_cube->corners[4]], corner_cubie_str[p_cube->corners[5]],
197    corner_cubie_str[p_cube->corners[6]], corner_cubie_str[p_cube->corners[7]]);
198 
199 return;
200 }
201 
202 
203 /* ========================================================================= */
print_inverse_cube(Cube * p_cube)204    void  print_inverse_cube(Cube  *p_cube)
205 /* ------------------------------------------------------------------------- */
206 
207 {
208 Cube                    cube_struc;
209 
210 
211 cube_inverse(p_cube, &cube_struc);
212 print_cube(&cube_struc);
213 
214 return;
215 }
216 
217 
218 /* ========================================================================= */
twist_f_cube(Cube * p_cube)219    void  twist_f_cube(Cube  *p_cube)
220 /* ------------------------------------------------------------------------- */
221 
222 {
223 four_cycle(p_cube->corners, CORNER_FLD, CORNER_FDR, CORNER_FRU, CORNER_FUL);
224 four_cycle(p_cube->corners, CORNER_DFL, CORNER_RFD, CORNER_UFR, CORNER_LFU);
225 four_cycle(p_cube->corners, CORNER_LDF, CORNER_DRF, CORNER_RUF, CORNER_ULF);
226 four_cycle(p_cube->edges, EDGE_FL, EDGE_FD, EDGE_FR, EDGE_FU);
227 four_cycle(p_cube->edges, EDGE_LF, EDGE_DF, EDGE_RF, EDGE_UF);
228 
229 return;
230 }
231 
232 
233 /* ========================================================================= */
twist_f2_cube(Cube * p_cube)234    void  twist_f2_cube(Cube  *p_cube)
235 /* ------------------------------------------------------------------------- */
236 
237 {
238 two_cycle(p_cube->corners, CORNER_FLD, CORNER_FRU);
239 two_cycle(p_cube->corners, CORNER_FDR, CORNER_FUL);
240 two_cycle(p_cube->corners, CORNER_DFL, CORNER_UFR);
241 two_cycle(p_cube->corners, CORNER_RFD, CORNER_LFU);
242 two_cycle(p_cube->corners, CORNER_LDF, CORNER_RUF);
243 two_cycle(p_cube->corners, CORNER_DRF, CORNER_ULF);
244 two_cycle(p_cube->edges, EDGE_FL, EDGE_FR);
245 two_cycle(p_cube->edges, EDGE_FD, EDGE_FU);
246 two_cycle(p_cube->edges, EDGE_LF, EDGE_RF);
247 two_cycle(p_cube->edges, EDGE_DF, EDGE_UF);
248 
249 return;
250 }
251 
252 
253 /* ========================================================================= */
twist_f3_cube(Cube * p_cube)254    void  twist_f3_cube(Cube  *p_cube)
255 /* ------------------------------------------------------------------------- */
256 
257 {
258 four_cycle(p_cube->corners, CORNER_FLD, CORNER_FUL, CORNER_FRU, CORNER_FDR);
259 four_cycle(p_cube->corners, CORNER_DFL, CORNER_LFU, CORNER_UFR, CORNER_RFD);
260 four_cycle(p_cube->corners, CORNER_LDF, CORNER_ULF, CORNER_RUF, CORNER_DRF);
261 four_cycle(p_cube->edges, EDGE_FL, EDGE_FU, EDGE_FR, EDGE_FD);
262 four_cycle(p_cube->edges, EDGE_LF, EDGE_UF, EDGE_RF, EDGE_DF);
263 
264 return;
265 }
266 
267 
268 /* ========================================================================= */
twist_r_cube(Cube * p_cube)269    void  twist_r_cube(Cube  *p_cube)
270 /* ------------------------------------------------------------------------- */
271 
272 {
273 four_cycle(p_cube->corners, CORNER_RFD, CORNER_RDB, CORNER_RBU, CORNER_RUF);
274 four_cycle(p_cube->corners, CORNER_DRF, CORNER_BRD, CORNER_URB, CORNER_FRU);
275 four_cycle(p_cube->corners, CORNER_FDR, CORNER_DBR, CORNER_BUR, CORNER_UFR);
276 four_cycle(p_cube->edges, EDGE_RF, EDGE_RD, EDGE_RB, EDGE_RU);
277 four_cycle(p_cube->edges, EDGE_FR, EDGE_DR, EDGE_BR, EDGE_UR);
278 
279 return;
280 }
281 
282 
283 /* ========================================================================= */
twist_r2_cube(Cube * p_cube)284    void  twist_r2_cube(Cube  *p_cube)
285 /* ------------------------------------------------------------------------- */
286 
287 {
288 two_cycle(p_cube->corners, CORNER_RFD, CORNER_RBU);
289 two_cycle(p_cube->corners, CORNER_RDB, CORNER_RUF);
290 two_cycle(p_cube->corners, CORNER_DRF, CORNER_URB);
291 two_cycle(p_cube->corners, CORNER_BRD, CORNER_FRU);
292 two_cycle(p_cube->corners, CORNER_FDR, CORNER_BUR);
293 two_cycle(p_cube->corners, CORNER_DBR, CORNER_UFR);
294 two_cycle(p_cube->edges, EDGE_RF, EDGE_RB);
295 two_cycle(p_cube->edges, EDGE_RD, EDGE_RU);
296 two_cycle(p_cube->edges, EDGE_FR, EDGE_BR);
297 two_cycle(p_cube->edges, EDGE_DR, EDGE_UR);
298 
299 return;
300 }
301 
302 
303 /* ========================================================================= */
twist_r3_cube(Cube * p_cube)304    void  twist_r3_cube(Cube  *p_cube)
305 /* ------------------------------------------------------------------------- */
306 
307 {
308 four_cycle(p_cube->corners, CORNER_RFD, CORNER_RUF, CORNER_RBU, CORNER_RDB);
309 four_cycle(p_cube->corners, CORNER_DRF, CORNER_FRU, CORNER_URB, CORNER_BRD);
310 four_cycle(p_cube->corners, CORNER_FDR, CORNER_UFR, CORNER_BUR, CORNER_DBR);
311 four_cycle(p_cube->edges, EDGE_RF, EDGE_RU, EDGE_RB, EDGE_RD);
312 four_cycle(p_cube->edges, EDGE_FR, EDGE_UR, EDGE_BR, EDGE_DR);
313 
314 return;
315 }
316 
317 
318 /* ========================================================================= */
twist_u_cube(Cube * p_cube)319    void  twist_u_cube(Cube  *p_cube)
320 /* ------------------------------------------------------------------------- */
321 
322 {
323 four_cycle(p_cube->corners, CORNER_URB, CORNER_UBL, CORNER_ULF, CORNER_UFR);
324 four_cycle(p_cube->corners, CORNER_BUR, CORNER_LUB, CORNER_FUL, CORNER_RUF);
325 four_cycle(p_cube->corners, CORNER_RBU, CORNER_BLU, CORNER_LFU, CORNER_FRU);
326 four_cycle(p_cube->edges, EDGE_UR, EDGE_UB, EDGE_UL, EDGE_UF);
327 four_cycle(p_cube->edges, EDGE_RU, EDGE_BU, EDGE_LU, EDGE_FU);
328 
329 return;
330 }
331 
332 
333 /* ========================================================================= */
twist_u2_cube(Cube * p_cube)334    void  twist_u2_cube(Cube  *p_cube)
335 /* ------------------------------------------------------------------------- */
336 
337 {
338 two_cycle(p_cube->corners, CORNER_URB, CORNER_ULF);
339 two_cycle(p_cube->corners, CORNER_UBL, CORNER_UFR);
340 two_cycle(p_cube->corners, CORNER_BUR, CORNER_FUL);
341 two_cycle(p_cube->corners, CORNER_LUB, CORNER_RUF);
342 two_cycle(p_cube->corners, CORNER_RBU, CORNER_LFU);
343 two_cycle(p_cube->corners, CORNER_BLU, CORNER_FRU);
344 two_cycle(p_cube->edges, EDGE_UR, EDGE_UL);
345 two_cycle(p_cube->edges, EDGE_UB, EDGE_UF);
346 two_cycle(p_cube->edges, EDGE_RU, EDGE_LU);
347 two_cycle(p_cube->edges, EDGE_BU, EDGE_FU);
348 
349 return;
350 }
351 
352 
353 /* ========================================================================= */
twist_u3_cube(Cube * p_cube)354    void  twist_u3_cube(Cube  *p_cube)
355 /* ------------------------------------------------------------------------- */
356 
357 {
358 four_cycle(p_cube->corners, CORNER_URB, CORNER_UFR, CORNER_ULF, CORNER_UBL);
359 four_cycle(p_cube->corners, CORNER_BUR, CORNER_RUF, CORNER_FUL, CORNER_LUB);
360 four_cycle(p_cube->corners, CORNER_RBU, CORNER_FRU, CORNER_LFU, CORNER_BLU);
361 four_cycle(p_cube->edges, EDGE_UR, EDGE_UF, EDGE_UL, EDGE_UB);
362 four_cycle(p_cube->edges, EDGE_RU, EDGE_FU, EDGE_LU, EDGE_BU);
363 
364 return;
365 }
366 
367 
368 /* ========================================================================= */
twist_b_cube(Cube * p_cube)369    void  twist_b_cube(Cube  *p_cube)
370 /* ------------------------------------------------------------------------- */
371 
372 {
373 four_cycle(p_cube->corners, CORNER_BRD, CORNER_BDL, CORNER_BLU, CORNER_BUR);
374 four_cycle(p_cube->corners, CORNER_DBR, CORNER_LBD, CORNER_UBL, CORNER_RBU);
375 four_cycle(p_cube->corners, CORNER_RDB, CORNER_DLB, CORNER_LUB, CORNER_URB);
376 four_cycle(p_cube->edges, EDGE_BR, EDGE_BD, EDGE_BL, EDGE_BU);
377 four_cycle(p_cube->edges, EDGE_RB, EDGE_DB, EDGE_LB, EDGE_UB);
378 
379 return;
380 }
381 
382 
383 /* ========================================================================= */
twist_b2_cube(Cube * p_cube)384    void  twist_b2_cube(Cube  *p_cube)
385 /* ------------------------------------------------------------------------- */
386 
387 {
388 two_cycle(p_cube->corners, CORNER_BRD, CORNER_BLU);
389 two_cycle(p_cube->corners, CORNER_BDL, CORNER_BUR);
390 two_cycle(p_cube->corners, CORNER_DBR, CORNER_UBL);
391 two_cycle(p_cube->corners, CORNER_LBD, CORNER_RBU);
392 two_cycle(p_cube->corners, CORNER_RDB, CORNER_LUB);
393 two_cycle(p_cube->corners, CORNER_DLB, CORNER_URB);
394 two_cycle(p_cube->edges, EDGE_BR, EDGE_BL);
395 two_cycle(p_cube->edges, EDGE_BD, EDGE_BU);
396 two_cycle(p_cube->edges, EDGE_RB, EDGE_LB);
397 two_cycle(p_cube->edges, EDGE_DB, EDGE_UB);
398 
399 return;
400 }
401 
402 
403 /* ========================================================================= */
twist_b3_cube(Cube * p_cube)404    void  twist_b3_cube(Cube  *p_cube)
405 /* ------------------------------------------------------------------------- */
406 
407 {
408 four_cycle(p_cube->corners, CORNER_BRD, CORNER_BUR, CORNER_BLU, CORNER_BDL);
409 four_cycle(p_cube->corners, CORNER_DBR, CORNER_RBU, CORNER_UBL, CORNER_LBD);
410 four_cycle(p_cube->corners, CORNER_RDB, CORNER_URB, CORNER_LUB, CORNER_DLB);
411 four_cycle(p_cube->edges, EDGE_BR, EDGE_BU, EDGE_BL, EDGE_BD);
412 four_cycle(p_cube->edges, EDGE_RB, EDGE_UB, EDGE_LB, EDGE_DB);
413 
414 return;
415 }
416 
417 
418 /* ========================================================================= */
twist_l_cube(Cube * p_cube)419    void  twist_l_cube(Cube  *p_cube)
420 /* ------------------------------------------------------------------------- */
421 
422 {
423 four_cycle(p_cube->corners, CORNER_LBD, CORNER_LDF, CORNER_LFU, CORNER_LUB);
424 four_cycle(p_cube->corners, CORNER_DLB, CORNER_FLD, CORNER_ULF, CORNER_BLU);
425 four_cycle(p_cube->corners, CORNER_BDL, CORNER_DFL, CORNER_FUL, CORNER_UBL);
426 four_cycle(p_cube->edges, EDGE_LB, EDGE_LD, EDGE_LF, EDGE_LU);
427 four_cycle(p_cube->edges, EDGE_BL, EDGE_DL, EDGE_FL, EDGE_UL);
428 
429 return;
430 }
431 
432 
433 /* ========================================================================= */
twist_l2_cube(Cube * p_cube)434    void  twist_l2_cube(Cube  *p_cube)
435 /* ------------------------------------------------------------------------- */
436 
437 {
438 two_cycle(p_cube->corners, CORNER_LBD, CORNER_LFU);
439 two_cycle(p_cube->corners, CORNER_LDF, CORNER_LUB);
440 two_cycle(p_cube->corners, CORNER_DLB, CORNER_ULF);
441 two_cycle(p_cube->corners, CORNER_FLD, CORNER_BLU);
442 two_cycle(p_cube->corners, CORNER_BDL, CORNER_FUL);
443 two_cycle(p_cube->corners, CORNER_DFL, CORNER_UBL);
444 two_cycle(p_cube->edges, EDGE_LB, EDGE_LF);
445 two_cycle(p_cube->edges, EDGE_LD, EDGE_LU);
446 two_cycle(p_cube->edges, EDGE_BL, EDGE_FL);
447 two_cycle(p_cube->edges, EDGE_DL, EDGE_UL);
448 
449 return;
450 }
451 
452 
453 /* ========================================================================= */
twist_l3_cube(Cube * p_cube)454    void  twist_l3_cube(Cube  *p_cube)
455 /* ------------------------------------------------------------------------- */
456 
457 {
458 four_cycle(p_cube->corners, CORNER_LBD, CORNER_LUB, CORNER_LFU, CORNER_LDF);
459 four_cycle(p_cube->corners, CORNER_DLB, CORNER_BLU, CORNER_ULF, CORNER_FLD);
460 four_cycle(p_cube->corners, CORNER_BDL, CORNER_UBL, CORNER_FUL, CORNER_DFL);
461 four_cycle(p_cube->edges, EDGE_LB, EDGE_LU, EDGE_LF, EDGE_LD);
462 four_cycle(p_cube->edges, EDGE_BL, EDGE_UL, EDGE_FL, EDGE_DL);
463 
464 return;
465 }
466 
467 
468 /* ========================================================================= */
twist_d_cube(Cube * p_cube)469    void  twist_d_cube(Cube  *p_cube)
470 /* ------------------------------------------------------------------------- */
471 
472 {
473 four_cycle(p_cube->corners, CORNER_DFL, CORNER_DLB, CORNER_DBR, CORNER_DRF);
474 four_cycle(p_cube->corners, CORNER_LDF, CORNER_BDL, CORNER_RDB, CORNER_FDR);
475 four_cycle(p_cube->corners, CORNER_FLD, CORNER_LBD, CORNER_BRD, CORNER_RFD);
476 four_cycle(p_cube->edges, EDGE_DF, EDGE_DL, EDGE_DB, EDGE_DR);
477 four_cycle(p_cube->edges, EDGE_FD, EDGE_LD, EDGE_BD, EDGE_RD);
478 
479 return;
480 }
481 
482 
483 /* ========================================================================= */
twist_d2_cube(Cube * p_cube)484    void  twist_d2_cube(Cube  *p_cube)
485 /* ------------------------------------------------------------------------- */
486 
487 {
488 two_cycle(p_cube->corners, CORNER_DFL, CORNER_DBR);
489 two_cycle(p_cube->corners, CORNER_DLB, CORNER_DRF);
490 two_cycle(p_cube->corners, CORNER_LDF, CORNER_RDB);
491 two_cycle(p_cube->corners, CORNER_BDL, CORNER_FDR);
492 two_cycle(p_cube->corners, CORNER_FLD, CORNER_BRD);
493 two_cycle(p_cube->corners, CORNER_LBD, CORNER_RFD);
494 two_cycle(p_cube->edges, EDGE_DF, EDGE_DB);
495 two_cycle(p_cube->edges, EDGE_DL, EDGE_DR);
496 two_cycle(p_cube->edges, EDGE_FD, EDGE_BD);
497 two_cycle(p_cube->edges, EDGE_LD, EDGE_RD);
498 
499 return;
500 }
501 
502 
503 /* ========================================================================= */
twist_d3_cube(Cube * p_cube)504    void  twist_d3_cube(Cube  *p_cube)
505 /* ------------------------------------------------------------------------- */
506 
507 {
508 four_cycle(p_cube->corners, CORNER_DFL, CORNER_DRF, CORNER_DBR, CORNER_DLB);
509 four_cycle(p_cube->corners, CORNER_LDF, CORNER_FDR, CORNER_RDB, CORNER_BDL);
510 four_cycle(p_cube->corners, CORNER_FLD, CORNER_RFD, CORNER_BRD, CORNER_LBD);
511 four_cycle(p_cube->edges, EDGE_DF, EDGE_DR, EDGE_DB, EDGE_DL);
512 four_cycle(p_cube->edges, EDGE_FD, EDGE_RD, EDGE_BD, EDGE_LD);
513 
514 return;
515 }
516 
517 
518 /* ========================================================================= */
user_twists_cube(Cube * p_cube)519    int  user_twists_cube(Cube  *p_cube)
520 /* ------------------------------------------------------------------------- */
521 
522 {
523 char                    line_str[2][MAX_INPUT_LENGTH], tw_str[3];
524 int                     num, ii;
525 
526 
527 printf("\nenter sequence:\n");
528 
529 if (fgets(line_str[0], MAX_INPUT_LENGTH, stdin) == NULL)
530    return -1;
531 
532 if (line_str[0][0] == '\n')
533    return -1;
534 
535 ii = 0;
536 
537 while (1)
538       {
539       num = sscanf(line_str[ii], "%2s%[^\n]", tw_str, line_str[1 - ii]);
540 
541       if (num < 1)
542          break;
543 
544       ii = 1 - ii;
545 
546       if (strcmp(tw_str, "F") == 0)
547          twist_f_cube(p_cube);
548       else if (strcmp(tw_str, "F2") == 0)
549          twist_f2_cube(p_cube);
550       else if (strcmp(tw_str, "F'") == 0)
551          twist_f3_cube(p_cube);
552       else if (strcmp(tw_str, "R") == 0)
553          twist_r_cube(p_cube);
554       else if (strcmp(tw_str, "R2") == 0)
555          twist_r2_cube(p_cube);
556       else if (strcmp(tw_str, "R'") == 0)
557          twist_r3_cube(p_cube);
558       else if (strcmp(tw_str, "U") == 0)
559          twist_u_cube(p_cube);
560       else if (strcmp(tw_str, "U2") == 0)
561          twist_u2_cube(p_cube);
562       else if (strcmp(tw_str, "U'") == 0)
563          twist_u3_cube(p_cube);
564       else if (strcmp(tw_str, "B") == 0)
565          twist_b_cube(p_cube);
566       else if (strcmp(tw_str, "B2") == 0)
567          twist_b2_cube(p_cube);
568       else if (strcmp(tw_str, "B'") == 0)
569          twist_b3_cube(p_cube);
570       else if (strcmp(tw_str, "L") == 0)
571          twist_l_cube(p_cube);
572       else if (strcmp(tw_str, "L2") == 0)
573          twist_l2_cube(p_cube);
574       else if (strcmp(tw_str, "L'") == 0)
575          twist_l3_cube(p_cube);
576       else if (strcmp(tw_str, "D") == 0)
577          twist_d_cube(p_cube);
578       else if (strcmp(tw_str, "D2") == 0)
579          twist_d2_cube(p_cube);
580       else if (strcmp(tw_str, "D'") == 0)
581          twist_d3_cube(p_cube);
582       else if (strcmp(tw_str, ".") == 0)
583          ;
584       else
585          {
586          printf("invalid twist: %s\n", tw_str);
587          return 1;
588          }
589 
590       if (num == 1)
591          break;
592       }
593 
594 return 0;
595 }
596 
597 
598 /* ========================================================================= */
main(void)599    int  main(void)
600 /* ------------------------------------------------------------------------- */
601 
602 {
603 Cube                    cube_struc;
604 int                     stat;
605 
606 
607 while (1)
608       {
609       cube_init(&cube_struc);
610       stat = user_twists_cube(&cube_struc);
611 
612       if (stat < 0)
613          break;
614 
615       if (stat == 0)
616          {
617          print_cube(&cube_struc);
618          print_inverse_cube(&cube_struc);
619          }
620       }
621 
622 exit(EXIT_SUCCESS);
623 
624 return 0;
625 }
626