File: twist.c

package info (click to toggle)
rubiks 20070912-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,052 kB
  • ctags: 1,046
  • sloc: cpp: 7,385; ansic: 7,350; makefile: 219
file content (625 lines) | stat: -rw-r--r-- 20,552 bytes parent folder | download | duplicates (5)
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
/*  twist.c  version 1.1  may 6, 2002  */


#include  <stdio.h>
#include  <stdlib.h>
#include  <string.h>


typedef struct cube
        {
        int             edges[24];
        int             corners[24];
        }
        Cube;


#define  MAX_INPUT_LENGTH                 1024


/*  number the corner cubies  */

#define  CORNER_UFR                          0
#define  CORNER_URB                          1
#define  CORNER_UBL                          2
#define  CORNER_ULF                          3
#define  CORNER_DRF                          4
#define  CORNER_DFL                          5
#define  CORNER_DLB                          6
#define  CORNER_DBR                          7

#define  CORNER_FRU                          8
#define  CORNER_RBU                          9
#define  CORNER_BLU                         10
#define  CORNER_LFU                         11
#define  CORNER_RFD                         12
#define  CORNER_FLD                         13
#define  CORNER_LBD                         14
#define  CORNER_BRD                         15

#define  CORNER_RUF                         16
#define  CORNER_BUR                         17
#define  CORNER_LUB                         18
#define  CORNER_FUL                         19
#define  CORNER_FDR                         20
#define  CORNER_LDF                         21
#define  CORNER_BDL                         22
#define  CORNER_RDB                         23


/*  number the edge cubies  */

#define  EDGE_UF                             0
#define  EDGE_UR                             1
#define  EDGE_UB                             2
#define  EDGE_UL                             3
#define  EDGE_DF                             4
#define  EDGE_DR                             5
#define  EDGE_DB                             6
#define  EDGE_DL                             7
#define  EDGE_FR                             8
#define  EDGE_FL                             9
#define  EDGE_BR                            10
#define  EDGE_BL                            11

#define  EDGE_FU                            12
#define  EDGE_RU                            13
#define  EDGE_BU                            14
#define  EDGE_LU                            15
#define  EDGE_FD                            16
#define  EDGE_RD                            17
#define  EDGE_BD                            18
#define  EDGE_LD                            19
#define  EDGE_RF                            20
#define  EDGE_LF                            21
#define  EDGE_RB                            22
#define  EDGE_LB                            23


static char            *edge_cubie_str[] = {"UF", "UR", "UB", "UL",
                                            "DF", "DR", "DB", "DL",
                                            "FR", "FL", "BR", "BL",
                                            "FU", "RU", "BU", "LU",
                                            "FD", "RD", "BD", "LD",
                                            "RF", "LF", "RB", "LB"};

static char            *corner_cubie_str[] = {"UFR", "URB", "UBL", "ULF",
                                              "DRF", "DFL", "DLB", "DBR", 
                                              "FRU", "RBU", "BLU", "LFU",
                                              "RFD", "FLD", "LBD", "BRD", 
                                              "RUF", "BUR", "LUB", "FUL",
                                              "FDR", "LDF", "BDL", "RDB"};


/* ========================================================================= */
   void  perm_n_init(int  nn, int  array_out[])
/* ------------------------------------------------------------------------- */

{
int                     ii;


for (ii = 0; ii < nn; ii++)
    array_out[ii] = ii;

return;
}


/* ========================================================================= */
   void  perm_n_inverse(int  nn, int  perm_in[], int  perm_out[])
/* ------------------------------------------------------------------------- */

{
int                     ii;


for (ii = 0; ii < nn; ii++)
    perm_out[perm_in[ii]] = ii;

return;
}


/* ========================================================================= */
   void  two_cycle(int  arr[], int  ind0, int  ind1)
/* ------------------------------------------------------------------------- */

{
int                     temp;


temp = arr[ind0];
arr[ind0] = arr[ind1];
arr[ind1] = temp;

return;
}


/* ========================================================================= */
   void  four_cycle(int  arr[], int  ind0, int  ind1, int  ind2, int  ind3)
/* ------------------------------------------------------------------------- */

{
int                     temp;


temp = arr[ind0];
arr[ind0] = arr[ind1];
arr[ind1] = arr[ind2];
arr[ind2] = arr[ind3];
arr[ind3] = temp;

return;
}


/* ========================================================================= */
   void  cube_init(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
perm_n_init(24, p_cube->edges);
perm_n_init(24, p_cube->corners);

return;
}


/* ========================================================================= */
   void  cube_inverse(Cube  *p_cube_in, Cube  *p_cube_out)
/* ------------------------------------------------------------------------- */

{
perm_n_inverse(24, p_cube_in->edges, p_cube_out->edges);
perm_n_inverse(24, p_cube_in->corners, p_cube_out->corners);

return;
}


/* ========================================================================= */
   void  print_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
printf("%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n",
       edge_cubie_str[p_cube->edges[0]], edge_cubie_str[p_cube->edges[1]],
       edge_cubie_str[p_cube->edges[2]], edge_cubie_str[p_cube->edges[3]],
       edge_cubie_str[p_cube->edges[4]], edge_cubie_str[p_cube->edges[5]],
       edge_cubie_str[p_cube->edges[6]], edge_cubie_str[p_cube->edges[7]],
       edge_cubie_str[p_cube->edges[8]], edge_cubie_str[p_cube->edges[9]],
       edge_cubie_str[p_cube->edges[10]], edge_cubie_str[p_cube->edges[11]],
   corner_cubie_str[p_cube->corners[0]], corner_cubie_str[p_cube->corners[1]],
   corner_cubie_str[p_cube->corners[2]], corner_cubie_str[p_cube->corners[3]],
   corner_cubie_str[p_cube->corners[4]], corner_cubie_str[p_cube->corners[5]],
   corner_cubie_str[p_cube->corners[6]], corner_cubie_str[p_cube->corners[7]]);

return;
}


/* ========================================================================= */
   void  print_inverse_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
Cube                    cube_struc;


cube_inverse(p_cube, &cube_struc);
print_cube(&cube_struc);

return;
}


/* ========================================================================= */
   void  twist_f_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
four_cycle(p_cube->corners, CORNER_FLD, CORNER_FDR, CORNER_FRU, CORNER_FUL);
four_cycle(p_cube->corners, CORNER_DFL, CORNER_RFD, CORNER_UFR, CORNER_LFU);
four_cycle(p_cube->corners, CORNER_LDF, CORNER_DRF, CORNER_RUF, CORNER_ULF);
four_cycle(p_cube->edges, EDGE_FL, EDGE_FD, EDGE_FR, EDGE_FU);
four_cycle(p_cube->edges, EDGE_LF, EDGE_DF, EDGE_RF, EDGE_UF);

return;
}


/* ========================================================================= */
   void  twist_f2_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
two_cycle(p_cube->corners, CORNER_FLD, CORNER_FRU);
two_cycle(p_cube->corners, CORNER_FDR, CORNER_FUL);
two_cycle(p_cube->corners, CORNER_DFL, CORNER_UFR);
two_cycle(p_cube->corners, CORNER_RFD, CORNER_LFU);
two_cycle(p_cube->corners, CORNER_LDF, CORNER_RUF);
two_cycle(p_cube->corners, CORNER_DRF, CORNER_ULF);
two_cycle(p_cube->edges, EDGE_FL, EDGE_FR);
two_cycle(p_cube->edges, EDGE_FD, EDGE_FU);
two_cycle(p_cube->edges, EDGE_LF, EDGE_RF);
two_cycle(p_cube->edges, EDGE_DF, EDGE_UF);

return;
}


/* ========================================================================= */
   void  twist_f3_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
four_cycle(p_cube->corners, CORNER_FLD, CORNER_FUL, CORNER_FRU, CORNER_FDR);
four_cycle(p_cube->corners, CORNER_DFL, CORNER_LFU, CORNER_UFR, CORNER_RFD);
four_cycle(p_cube->corners, CORNER_LDF, CORNER_ULF, CORNER_RUF, CORNER_DRF);
four_cycle(p_cube->edges, EDGE_FL, EDGE_FU, EDGE_FR, EDGE_FD);
four_cycle(p_cube->edges, EDGE_LF, EDGE_UF, EDGE_RF, EDGE_DF);

return;
}


/* ========================================================================= */
   void  twist_r_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
four_cycle(p_cube->corners, CORNER_RFD, CORNER_RDB, CORNER_RBU, CORNER_RUF);
four_cycle(p_cube->corners, CORNER_DRF, CORNER_BRD, CORNER_URB, CORNER_FRU);
four_cycle(p_cube->corners, CORNER_FDR, CORNER_DBR, CORNER_BUR, CORNER_UFR);
four_cycle(p_cube->edges, EDGE_RF, EDGE_RD, EDGE_RB, EDGE_RU);
four_cycle(p_cube->edges, EDGE_FR, EDGE_DR, EDGE_BR, EDGE_UR);

return;
}


/* ========================================================================= */
   void  twist_r2_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
two_cycle(p_cube->corners, CORNER_RFD, CORNER_RBU);
two_cycle(p_cube->corners, CORNER_RDB, CORNER_RUF);
two_cycle(p_cube->corners, CORNER_DRF, CORNER_URB);
two_cycle(p_cube->corners, CORNER_BRD, CORNER_FRU);
two_cycle(p_cube->corners, CORNER_FDR, CORNER_BUR);
two_cycle(p_cube->corners, CORNER_DBR, CORNER_UFR);
two_cycle(p_cube->edges, EDGE_RF, EDGE_RB);
two_cycle(p_cube->edges, EDGE_RD, EDGE_RU);
two_cycle(p_cube->edges, EDGE_FR, EDGE_BR);
two_cycle(p_cube->edges, EDGE_DR, EDGE_UR);

return;
}


/* ========================================================================= */
   void  twist_r3_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
four_cycle(p_cube->corners, CORNER_RFD, CORNER_RUF, CORNER_RBU, CORNER_RDB);
four_cycle(p_cube->corners, CORNER_DRF, CORNER_FRU, CORNER_URB, CORNER_BRD);
four_cycle(p_cube->corners, CORNER_FDR, CORNER_UFR, CORNER_BUR, CORNER_DBR);
four_cycle(p_cube->edges, EDGE_RF, EDGE_RU, EDGE_RB, EDGE_RD);
four_cycle(p_cube->edges, EDGE_FR, EDGE_UR, EDGE_BR, EDGE_DR);

return;
}


/* ========================================================================= */
   void  twist_u_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
four_cycle(p_cube->corners, CORNER_URB, CORNER_UBL, CORNER_ULF, CORNER_UFR);
four_cycle(p_cube->corners, CORNER_BUR, CORNER_LUB, CORNER_FUL, CORNER_RUF);
four_cycle(p_cube->corners, CORNER_RBU, CORNER_BLU, CORNER_LFU, CORNER_FRU);
four_cycle(p_cube->edges, EDGE_UR, EDGE_UB, EDGE_UL, EDGE_UF);
four_cycle(p_cube->edges, EDGE_RU, EDGE_BU, EDGE_LU, EDGE_FU);

return;
}


/* ========================================================================= */
   void  twist_u2_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
two_cycle(p_cube->corners, CORNER_URB, CORNER_ULF);
two_cycle(p_cube->corners, CORNER_UBL, CORNER_UFR);
two_cycle(p_cube->corners, CORNER_BUR, CORNER_FUL);
two_cycle(p_cube->corners, CORNER_LUB, CORNER_RUF);
two_cycle(p_cube->corners, CORNER_RBU, CORNER_LFU);
two_cycle(p_cube->corners, CORNER_BLU, CORNER_FRU);
two_cycle(p_cube->edges, EDGE_UR, EDGE_UL);
two_cycle(p_cube->edges, EDGE_UB, EDGE_UF);
two_cycle(p_cube->edges, EDGE_RU, EDGE_LU);
two_cycle(p_cube->edges, EDGE_BU, EDGE_FU);

return;
}


/* ========================================================================= */
   void  twist_u3_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
four_cycle(p_cube->corners, CORNER_URB, CORNER_UFR, CORNER_ULF, CORNER_UBL);
four_cycle(p_cube->corners, CORNER_BUR, CORNER_RUF, CORNER_FUL, CORNER_LUB);
four_cycle(p_cube->corners, CORNER_RBU, CORNER_FRU, CORNER_LFU, CORNER_BLU);
four_cycle(p_cube->edges, EDGE_UR, EDGE_UF, EDGE_UL, EDGE_UB);
four_cycle(p_cube->edges, EDGE_RU, EDGE_FU, EDGE_LU, EDGE_BU);

return;
}


/* ========================================================================= */
   void  twist_b_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
four_cycle(p_cube->corners, CORNER_BRD, CORNER_BDL, CORNER_BLU, CORNER_BUR);
four_cycle(p_cube->corners, CORNER_DBR, CORNER_LBD, CORNER_UBL, CORNER_RBU);
four_cycle(p_cube->corners, CORNER_RDB, CORNER_DLB, CORNER_LUB, CORNER_URB);
four_cycle(p_cube->edges, EDGE_BR, EDGE_BD, EDGE_BL, EDGE_BU);
four_cycle(p_cube->edges, EDGE_RB, EDGE_DB, EDGE_LB, EDGE_UB);

return;
}


/* ========================================================================= */
   void  twist_b2_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
two_cycle(p_cube->corners, CORNER_BRD, CORNER_BLU);
two_cycle(p_cube->corners, CORNER_BDL, CORNER_BUR);
two_cycle(p_cube->corners, CORNER_DBR, CORNER_UBL);
two_cycle(p_cube->corners, CORNER_LBD, CORNER_RBU);
two_cycle(p_cube->corners, CORNER_RDB, CORNER_LUB);
two_cycle(p_cube->corners, CORNER_DLB, CORNER_URB);
two_cycle(p_cube->edges, EDGE_BR, EDGE_BL);
two_cycle(p_cube->edges, EDGE_BD, EDGE_BU);
two_cycle(p_cube->edges, EDGE_RB, EDGE_LB);
two_cycle(p_cube->edges, EDGE_DB, EDGE_UB);

return;
}


/* ========================================================================= */
   void  twist_b3_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
four_cycle(p_cube->corners, CORNER_BRD, CORNER_BUR, CORNER_BLU, CORNER_BDL);
four_cycle(p_cube->corners, CORNER_DBR, CORNER_RBU, CORNER_UBL, CORNER_LBD);
four_cycle(p_cube->corners, CORNER_RDB, CORNER_URB, CORNER_LUB, CORNER_DLB);
four_cycle(p_cube->edges, EDGE_BR, EDGE_BU, EDGE_BL, EDGE_BD);
four_cycle(p_cube->edges, EDGE_RB, EDGE_UB, EDGE_LB, EDGE_DB);

return;
}


/* ========================================================================= */
   void  twist_l_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
four_cycle(p_cube->corners, CORNER_LBD, CORNER_LDF, CORNER_LFU, CORNER_LUB);
four_cycle(p_cube->corners, CORNER_DLB, CORNER_FLD, CORNER_ULF, CORNER_BLU);
four_cycle(p_cube->corners, CORNER_BDL, CORNER_DFL, CORNER_FUL, CORNER_UBL);
four_cycle(p_cube->edges, EDGE_LB, EDGE_LD, EDGE_LF, EDGE_LU);
four_cycle(p_cube->edges, EDGE_BL, EDGE_DL, EDGE_FL, EDGE_UL);

return;
}


/* ========================================================================= */
   void  twist_l2_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
two_cycle(p_cube->corners, CORNER_LBD, CORNER_LFU);
two_cycle(p_cube->corners, CORNER_LDF, CORNER_LUB);
two_cycle(p_cube->corners, CORNER_DLB, CORNER_ULF);
two_cycle(p_cube->corners, CORNER_FLD, CORNER_BLU);
two_cycle(p_cube->corners, CORNER_BDL, CORNER_FUL);
two_cycle(p_cube->corners, CORNER_DFL, CORNER_UBL);
two_cycle(p_cube->edges, EDGE_LB, EDGE_LF);
two_cycle(p_cube->edges, EDGE_LD, EDGE_LU);
two_cycle(p_cube->edges, EDGE_BL, EDGE_FL);
two_cycle(p_cube->edges, EDGE_DL, EDGE_UL);

return;
}


/* ========================================================================= */
   void  twist_l3_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
four_cycle(p_cube->corners, CORNER_LBD, CORNER_LUB, CORNER_LFU, CORNER_LDF);
four_cycle(p_cube->corners, CORNER_DLB, CORNER_BLU, CORNER_ULF, CORNER_FLD);
four_cycle(p_cube->corners, CORNER_BDL, CORNER_UBL, CORNER_FUL, CORNER_DFL);
four_cycle(p_cube->edges, EDGE_LB, EDGE_LU, EDGE_LF, EDGE_LD);
four_cycle(p_cube->edges, EDGE_BL, EDGE_UL, EDGE_FL, EDGE_DL);

return;
}


/* ========================================================================= */
   void  twist_d_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
four_cycle(p_cube->corners, CORNER_DFL, CORNER_DLB, CORNER_DBR, CORNER_DRF);
four_cycle(p_cube->corners, CORNER_LDF, CORNER_BDL, CORNER_RDB, CORNER_FDR);
four_cycle(p_cube->corners, CORNER_FLD, CORNER_LBD, CORNER_BRD, CORNER_RFD);
four_cycle(p_cube->edges, EDGE_DF, EDGE_DL, EDGE_DB, EDGE_DR);
four_cycle(p_cube->edges, EDGE_FD, EDGE_LD, EDGE_BD, EDGE_RD);

return;
}


/* ========================================================================= */
   void  twist_d2_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
two_cycle(p_cube->corners, CORNER_DFL, CORNER_DBR);
two_cycle(p_cube->corners, CORNER_DLB, CORNER_DRF);
two_cycle(p_cube->corners, CORNER_LDF, CORNER_RDB);
two_cycle(p_cube->corners, CORNER_BDL, CORNER_FDR);
two_cycle(p_cube->corners, CORNER_FLD, CORNER_BRD);
two_cycle(p_cube->corners, CORNER_LBD, CORNER_RFD);
two_cycle(p_cube->edges, EDGE_DF, EDGE_DB);
two_cycle(p_cube->edges, EDGE_DL, EDGE_DR);
two_cycle(p_cube->edges, EDGE_FD, EDGE_BD);
two_cycle(p_cube->edges, EDGE_LD, EDGE_RD);

return;
}


/* ========================================================================= */
   void  twist_d3_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
four_cycle(p_cube->corners, CORNER_DFL, CORNER_DRF, CORNER_DBR, CORNER_DLB);
four_cycle(p_cube->corners, CORNER_LDF, CORNER_FDR, CORNER_RDB, CORNER_BDL);
four_cycle(p_cube->corners, CORNER_FLD, CORNER_RFD, CORNER_BRD, CORNER_LBD);
four_cycle(p_cube->edges, EDGE_DF, EDGE_DR, EDGE_DB, EDGE_DL);
four_cycle(p_cube->edges, EDGE_FD, EDGE_RD, EDGE_BD, EDGE_LD);

return;
}


/* ========================================================================= */
   int  user_twists_cube(Cube  *p_cube)
/* ------------------------------------------------------------------------- */

{
char                    line_str[2][MAX_INPUT_LENGTH], tw_str[3];
int                     num, ii;


printf("\nenter sequence:\n");

if (fgets(line_str[0], MAX_INPUT_LENGTH, stdin) == NULL)
   return -1;

if (line_str[0][0] == '\n')
   return -1;

ii = 0;

while (1)
      {
      num = sscanf(line_str[ii], "%2s%[^\n]", tw_str, line_str[1 - ii]);

      if (num < 1)
         break;

      ii = 1 - ii;

      if (strcmp(tw_str, "F") == 0)
         twist_f_cube(p_cube);
      else if (strcmp(tw_str, "F2") == 0)
         twist_f2_cube(p_cube);
      else if (strcmp(tw_str, "F'") == 0)
         twist_f3_cube(p_cube);
      else if (strcmp(tw_str, "R") == 0)
         twist_r_cube(p_cube);
      else if (strcmp(tw_str, "R2") == 0)
         twist_r2_cube(p_cube);
      else if (strcmp(tw_str, "R'") == 0)
         twist_r3_cube(p_cube);
      else if (strcmp(tw_str, "U") == 0)
         twist_u_cube(p_cube);
      else if (strcmp(tw_str, "U2") == 0)
         twist_u2_cube(p_cube);
      else if (strcmp(tw_str, "U'") == 0)
         twist_u3_cube(p_cube);
      else if (strcmp(tw_str, "B") == 0)
         twist_b_cube(p_cube);
      else if (strcmp(tw_str, "B2") == 0)
         twist_b2_cube(p_cube);
      else if (strcmp(tw_str, "B'") == 0)
         twist_b3_cube(p_cube);
      else if (strcmp(tw_str, "L") == 0)
         twist_l_cube(p_cube);
      else if (strcmp(tw_str, "L2") == 0)
         twist_l2_cube(p_cube);
      else if (strcmp(tw_str, "L'") == 0)
         twist_l3_cube(p_cube);
      else if (strcmp(tw_str, "D") == 0)
         twist_d_cube(p_cube);
      else if (strcmp(tw_str, "D2") == 0)
         twist_d2_cube(p_cube);
      else if (strcmp(tw_str, "D'") == 0)
         twist_d3_cube(p_cube);
      else if (strcmp(tw_str, ".") == 0)
         ;
      else
         {
         printf("invalid twist: %s\n", tw_str);
         return 1;
         }

      if (num == 1)
         break;
      }

return 0;
}


/* ========================================================================= */
   int  main(void)
/* ------------------------------------------------------------------------- */

{
Cube                    cube_struc;
int                     stat;


while (1)
      {
      cube_init(&cube_struc);
      stat = user_twists_cube(&cube_struc);

      if (stat < 0)
         break;

      if (stat == 0)
         {
         print_cube(&cube_struc);
         print_inverse_cube(&cube_struc);
         }
      }

exit(EXIT_SUCCESS);

return 0;
}