TweetFollow Us on Twitter

Feb 95 Challenge
Volume Number:11
Issue Number:2
Column Tag:Programmer’s Challenge

Programmer’s Challenge

By Mike Scanlin, Mountain View, CA

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Symbolize

This month’s challenge was anonymously suggested. The goal is to make the output of a non-symbolic disassembler into a symbolic disassembly. The output file of the non-symbolic disassembler looks like this:

0006CDDE   RTS
0006CDE0   LINK     A6,#$0000
0006CDE4   MOVE.L   A4,-(A7)
0006CDE6   JSR      0006CE12
etc.

The symbol file you are given looks like this (and, yes, the real file I use for testing will have the LowMem and HiMem values in it so that you’ll be able to find a symbol for any address):

00000000 LowMem
0006CDDE Foo
0006CDE0 MyFunction
0006CE12 MyOtherFunction
FFFFFFFF HiMem

Your job is to take every 8 byte hex value in the input disassembly and look it up in the symbol file and then substitute the symbol (and offset) for the value. If you ran your routine on the above fragment then the output would be this:

[Foo          ]  RTS
[MyFunction   ]  LINK     A6,#$0000
[MyFunction+4 ]  MOVE.L   A4,-(A7)
[MyFunction+6 ]  JSR      MyOtherFunction

The prototype of the function you write is:

void
Symbolize(inputFile, symbolFile, outputFile, symLength)
FILE    *inputFile;
FILE    *symbolFile;
FILE    *outputFile;
unsigned short symLength;

InputFile is a standard C input stream containing the non-symbolic disassembly (as ASCII text). SymbolFile is a standard C input stream containing addresses (as ASCII text, not binary) and symbols (sorted by address, lowest to highest). The first symbol is for address 00000000 and the last symbol is for address FFFFFFFF, as shown in the example above. OutputFile is a standard C output stream that you send the symbolized disassembly to (also ASCII text). There is no need to fopen or fclose any of these streams (my test bench program will do it for you).

SymLength is the number of characters between the ‘[‘ and ‘]’ in the outputFile (which will range from 12 to 32). All expressions of the form <symbolName>+<offset from symbol in base 10> should be exactly symLength characters long. Pad with spaces on the right if it’s shorter and remove characters from the right side of symbolName if it’s longer (always have the complete offset, unless it’s zero). SymLength is 13 in the example above.

The largest symbolFile you’ll receive is 512K and the largest inputFile you’ll receive is 50K. You can assume that you’ll have enough space for the outputFile. Before returning, your routine should dispose of any memory it might allocate.

Unlike some previous Challenges where you were allowed to write an untimed Initialize routine, there is no Initialize routine this month. The time it takes you to parse the symbolFile will be included in your overall time. The average inputFile will be 20K and contain 800 addresses to look up. The average symbolTable will contain 2000 symbols.

E-mail me if you have any questions. Have fun.

Two Months Ago Winner

Congratulations to Challenge Champion Bob Boonstra (Westford, MA) for earning his sixth win in the Rubik’s Cube Challenge. This is a special month for Bob because he has decided to retire from Programming Challenges and become the first person to enter the Programmer’s Challenge Hall of Fame. Bob included this note along with his entry:

Should I be so fortunate as to win, I would like to announce my retirement from regular Programmer's Challenge competition. I may enter occasionally, particularly for any assembly language challenges or PowerMac challenges, but I want to devote more time to other pursuits. Besides, it's time to give someone else a chance. I have truly enjoyed the Challenges, and I commend Mike for keeping people focused on efficiency.

- Bob Boonstra

Well, Bob, thanks for playing. We’ve all enjoyed learning optimization tricks from a master programmer during the last couple of years. I’m sure it will be a while before anyone collects as many wins as you have to take away your title.

Here are the times and code sizes for each entry. Numbers in parens after a person’s name indicate how many times that person has finished in the top 5 places of all previous Programmer Challenges, not including this one:

Name time code+data

Bob Boonstra (13) 79 72,892

Ernst Munter (4) 156 4,526

Allen Stenger (8) 222 9,872

Robert Hearn 266 4,492

Jim Lloyd (1) 900 33,044

As always, Bob’s code is well commented and fun to read. In addition to studying it for efficiency tips (and interesting macro definitions) you can bet that I’ll be watching the moves it makes to try and learn how to put my cube back to its initial state. Maybe someday I’ll be able to solve any cube in the theoretical 22 or 23 moves. Right, and maybe monkeys will fly out of my butt, too...

SolveRubiksCube

Copyright (c) 1994  J Robert Boonstra

This source has been edited for length. The entire source is available at the usual online sites. Please see page 2 for details.

Problem Statement

Solve Rubiks cube, given an initial state by a call to MikeCubeToRubiksCube. Provide access to solution progress via RubiksCubeToMikeCube. Return 1 when cube is solved, 0 after an intermediate move, and -1 if the cube is unsolvable.

Background

Although it hasn’t been proven, it is believed that “God’s algorithm” for solving the cube requires something like 22 or 23 moves in the worst case. Back in the 1970s, when the cube was introduced, Singmaster and Thistlethwaite published solutions that solve the cube in ~52 moves, and that result has probably been improved upon since then. (These numbers may count half-turns as a single move instead of two quarter-turn moves - some people prefer to count that way.) For those interested in the cube, there is an active mailing list - send mail to cube-lovers-request@ai.mit.edu for more info. In the event that Singmaster, Thistlethwaite, God, or an avid cube-lover doesn’t enter the challenge, we offer this solution.

Solution strategy

This solution is based on the now out-of-print book by Don Taylor, entitled Mastering Rubik’s Cube, and sold at the time for the princely sum of $1.95. While not in any way optimal, the solution in the book has the advantage of being (relatively) easy to remember.

We solve the cube using the following steps:

1. Solve the edge cubes in the top layer.

2. Solve the corner cubes in the top layer.

3. Solve the (edge) cubes in the middle layer.

4. Move the bottom layer corner cubes to the correct position.

5. Orient the bottom layer corner cubes correctly.

6. Move the bottom layer edge cubes to the correct position.

7. Orient the bottom layer edge cubes correctly.


This solution trades a large amount of space (code) for speed. The operators that transform the cube are coded as macros, rather than as subroutines. (These macros were generated by an auxiliary program.)

rubik.c

#pragma options(honor_register,assign_registers)
#include "rubik.h"
#include "transform.h"

char *theMoveP;    /* pointer to stored moves */
char *lastMoveP;   /* pointer to final move */
short firstTime;   /* set to 1 by MikeCubeToRubiksCube */

int SolveRubiksCube(register RubiksCube *rub)
{
register unsigned short ch;
  if (firstTime) {

// First time through, check to see if the cube is legal.  Check for existence of the 
// required corners/edges.  (We also could check the twist on the corners and the  flip 
//parity on the edges to ensure that the cube is solvable, but I never got that working.)
      if (!LegalCube(rub)) return(-1);
//Find complete solution on first call.  Play back on subsequent calls.  Initial solution //split into subroutine 
calls to deal with Symantec C limit on code in one file.
   SolveTopEdgesFR(rub);
   SolveTopEdgesLB(rub);
   if (!SolveTopCorners(rub)) return (-1);
   if (!SolveMiddleLayer(rub)) return (-1);
   if (!SolveBottomCorners(rub)) return (-1);
   if (!SolveBottomEdges(rub)) return (-1);
   firstTime = 0;

// Restore the initial cube state so that we can play back the moves one at a time.
   lastMoveP = theMoveP;
   theMoveP = rub->theMove;
   {
     register long *p=(long *)&rub->cubie[0][0];
     register ct=16*8/sizeof(long);
     do {
       *p = *(p+ 16*8/sizeof(long));
       ++p;
     } while (--ct);
   }
  }
  ch = *theMoveP;
  switch (ch) {
    case U: U1move; break;
    case F: F1move; break;
    case L: L1move; break;
    case D: D1move; break;
    case B: B1move; break;
    case R: R1move; break;
    case u: U3move; break;
    case f: F3move; break;
    case l: L3move; break;
    case d: D3move; break;
    case b: B3move; break;
    case r: R3move; break;
    }
  return (lastMoveP == ++theMoveP);
}

#define CornerVal(X,Y,Z) \
  ((1<(X##Y##Z##_##X)) | (1<X##Y##Z##_##Y) | \
                          (1<X##Y##Z##_##Z))
#define EdgeVal(X,Z) \
  ((1<(X##Z##_##X)) |  (1<X##Z##_##Z))
#define crn(a,b,c)  ((1<a) | (1<b) | (1<c))
#define edg(a,b)    ((1<a) | (1<b))

static Boolean LegalCube(RubiksCube *rub)
{
char cubeValues[20];
register long whichCubes=0;
register char *valP;
register short count,theVal;
  
// Make certain all the necessary corner cubes are there.
  valP = cubeValues;
  *valP++ = CornerVal(U,L,F);
  *valP++ = CornerVal(U,R,F);
  *valP++ = CornerVal(U,L,B);
  *valP++ = CornerVal(U,R,B);
  *valP++ = CornerVal(D,L,F);
  *valP++ = CornerVal(D,R,F);
  *valP++ = CornerVal(D,L,B);
  *valP++ = CornerVal(D,R,B);
  
  valP = cubeValues;
  count=8;
  whichCubes=0;
  do {
    theVal = *valP++;
    if (theVal == crn(U,L,F)) {whichCubes|=0x01; continue;}
    if (theVal == crn(U,R,F)) {whichCubes|=0x02; continue;}
    if (theVal == crn(U,L,B)) {whichCubes|=0x04; continue;}
    if (theVal == crn(U,R,B)) {whichCubes|=0x08; continue;}
    if (theVal == crn(D,L,F)) {whichCubes|=0x10; continue;}
    if (theVal == crn(D,R,F)) {whichCubes|=0x20; continue;}
    if (theVal == crn(D,L,B)) {whichCubes|=0x40; continue;}
    if (theVal == crn(D,R,B)) {whichCubes|=0x80; continue;}
    return false;
  } while (--count);
  if (whichCubes != 0xFF) return false;

// Make certain all the necessary edge cubes are there.
  valP = cubeValues+8;
  *valP++ = EdgeVal(U,L); *valP++ = EdgeVal(U,R);
  *valP++ = EdgeVal(D,L); *valP++ = EdgeVal(D,R);
  *valP++ = EdgeVal(U,F); *valP++ = EdgeVal(U,B);
  *valP++ = EdgeVal(D,F); *valP++ = EdgeVal(D,B);
  *valP++ = EdgeVal(L,F); *valP++ = EdgeVal(L,B);
  *valP++ = EdgeVal(R,F); *valP++ = EdgeVal(R,B);

  valP = cubeValues+8;
  count=12;
  whichCubes=0;
  do {
    theVal = *valP++;
    if (theVal == edg(U,L)) {whichCubes|=0x0001; continue;}
    if (theVal == edg(U,R)) {whichCubes|=0x0002; continue;}
    if (theVal == edg(D,L)) {whichCubes|=0x0004; continue;}
    if (theVal == edg(D,R)) {whichCubes|=0x0008; continue;}
    if (theVal == edg(U,F)) {whichCubes|=0x0010; continue;}
    if (theVal == edg(U,B)) {whichCubes|=0x0020; continue;}
    if (theVal == edg(D,F)) {whichCubes|=0x0040; continue;}
    if (theVal == edg(D,B)) {whichCubes|=0x0080; continue;}
    if (theVal == edg(L,F)) {whichCubes|=0x0100; continue;}
    if (theVal == edg(L,B)) {whichCubes|=0x0200; continue;}
    if (theVal == edg(R,F)) {whichCubes|=0x0400; continue;}
    if (theVal == edg(R,B)) {whichCubes|=0x0800; continue;}
    return false;
  } while (--count);
  if (whichCubes != 0xFFF) return false;

  return (true);
}

rubik.h

 TYPEDEFS and DEFINES
typedef struct CubeSide {
  char littleSquare[3][3];
} CubeSide;

typedef struct MikeCube {
  CubeSide face[6];
} MikeCube;

// face ordering in MikeCube
enum {kTop=0, kLeft, kFront, kRight, kBottom, kBack};

typedef struct RubiksCube {
  char cubie[16][8];
  char origCube[16][8];
  char theMove[512];
} RubiksCube, *RubiksCubePtr;

// face ordering in RubiksCube
enum { F=0,L,R,B,U,D,f,l,r,b,u,d};

// Macros Front(x) give access to individual cubies on the Front face.  
// Similarly for other faces.
#define Front(x)  rub->cubie[x][0]
#define Left(x)   rub->cubie[x][1]
#define Right(x)  rub->cubie[x][2]
#define Back(x)   rub->cubie[x][3]
#define Up(x)     rub->cubie[x][4]
#define Down(x)   rub->cubie[x][5]

// Set up symbols to represent individual cubie faces
#define ULF_F Front(0)
#define UF_F  Front(1)
#define URF_F Front(2)
#define LF_F  Front(3)
#define RF_F  Front(5)
#define DLF_F Front(6)
#define DF_F  Front(7)
#define DRF_F Front(8)

#define ULB_L Left(0)
#define UL_L  Left(1)
#define ULF_L Left(2)
#define LB_L  Left(3)
#define LF_L  Left(5)
#define DLB_L Left(6)
#define DL_L  Left(7)
#define DLF_L Left(8)

#define URF_R Right(0)
#define UR_R  Right(1)
#define URB_R Right(2)
#define RF_R  Right(3)
#define RB_R  Right(5)
#define DRF_R Right(6)
#define DR_R  Right(7)
#define DRB_R Right(8)

#define DLF_D Down(0)
#define DF_D  Down(1)
#define DRF_D Down(2)
#define DL_D  Down(3)
#define DR_D  Down(5)
#define DLB_D Down(6)
#define DB_D  Down(7)
#define DRB_D Down(8)

#define DLB_B Back(0)
#define DB_B  Back(1)
#define DRB_B Back(2)
#define LB_B  Back(3)
#define RB_B  Back(5)
#define ULB_B Back(6)
#define UB_B  Back(7)
#define URB_B Back(8)

#define ULB_U Up(0)
#define UB_U  Up(1)
#define URB_U Up(2)
#define UL_U  Up(3)
#define UR_U  Up(5)
#define ULF_U Up(6)
#define UF_U  Up(7)
#define URF_U Up(8)

/*
Macro M(x) records the individual turns in the transformation for playback during subsequent calls to SolveRubiksCube.
 */
#define M(x)   *theMoveP++ = x;
#define Rot2(a,b) \
{register char tmp; tmp=a; a=b; b=tmp;}
#define Rot3(a,b,c) \
{register char tmp; tmp=a; a=b; b=c; c=tmp;}
#define Rot4(a,b,c,d) \
{register char tmp; tmp=a; a=b; b=c; c=d; d=tmp;}
#define Rot5(a,b,c,d,e) \
{register char tmp; tmp=a; a=b; b=c; c=d; d=e; e=tmp;}
#define Rot6(a,b,c,d,e,f) \
{register char tmp; tmp=a; a=b; b=c; c=d; d=e; e=f; f=tmp;}
#define Rot7(a,b,c,d,e,f,g) \
{register char tmp;tmp=a;a=b;b=c;c=d;d=e;e=f;f=g;g=tmp;}
#define Rot8(a,b,c,d,e,f,g,h) \
{register char tmp;tmp=a;a=b;b=c;c=d;d=e;e=f;f=g;g=h;h=tmp;}
#define Rot9(a,b,c,d,e,f,g,h,i) \
{register char tmp;tmp=a;a=b;b=c;c=d;d=e;e=f;f=g;g=h;h=i; \
                     i=tmp;}
#define Rot10(a,b,c,d,e,f,g,h,i,j) \
{register char tmp;tmp=a;a=b;b=c;c=d;d=e;e=f;f=g;g=h;h=i; \
                         i=j;j=tmp;}
#define Rot12(a,b,c,d,e,f,g,h,i,j,k,l) \
{register char tmp;tmp=a;a=b;b=c;c=d;d=e;e=f;f=g;g=h;h=i; \
                     i=j;j=k;k=l;l=tmp;}
#define Rot15(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) \
{register char tmp;tmp=a;a=b;b=c;c=d;d=e;e=f;f=g;g=h;h=i; \
                     i=j;j=k;k=l;l=m;m=n;n=o;o=tmp;}
#define Rot16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
{register char tmp;tmp=a;a=b;b=c;c=d;d=e;e=f;f=g;g=h;h=i; \
                     i=j;j=k;k=l;l=m;m=n;n=o;o=p;p=tmp;}
#define CornerEquals(X,Y,Z,a,b,c) \
((X##Y##Z##_##X==a||X##Y##Z##_##X==b||X##Y##Z##_##X==c) && \
 (X##Y##Z##_##Y==a||X##Y##Z##_##Y==b||X##Y##Z##_##Y==c) && \
 (X##Y##Z##_##Z==a||X##Y##Z##_##Z==b||X##Y##Z##_##Z==c))

#define CornerCorrect(X,Y,Z) \
((X##Y##Z##_##X==X||X##Y##Z##_##X==Y||X##Y##Z##_##X==Z) && \
 (X##Y##Z##_##Y==X||X##Y##Z##_##Y==Y||X##Y##Z##_##Y==Z) && \
 (X##Y##Z##_##Z==X||X##Y##Z##_##Z==Y||X##Y##Z##_##Z==Z))


PROTOTYPES
int SolveRubiksCube(RubiksCube *cubePtr);
int FindSolution(void);

void MikeCubeToRubiksCube(MikeCube *mikePtr, 
                                    RubiksCube *rubikPtr);
void RubiksCubeToMikeCube(RubiksCube *rubikPtr, 
                                      MikeCube *mikePtr);
void SolveTopEdgesFR(RubiksCube *rubPtr);
void SolveTopEdgesLB(RubiksCube *rubPtr);
Boolean SolveTopCorners(RubiksCube *rubPtr);
Boolean SolveMiddleLayer(RubiksCube *rubPtr);
Boolean SolveBottomCorners(RubiksCube *rubPtr);
Boolean SolveBottomEdges(RubiksCube *rubPtr);
Boolean LegalCube(RubiksCube *rubPtr);

extern char *theMoveP;    /* pointer to stored moves */
extern short firstTime;

convert.c

#include "rubik.h"

/* mapping of MikeCube faces to RubiksCube faces */
char rubikFaceOrder[] =  {F,L,R,B,U,D};
char mikeToRubik[] =     {U,L,F,R,D,B};
char rubikToMike[] =
                {kFront,kLeft,kRight,kBack,kTop,kBottom};
char mikeColorToRubik[6];
char rubikColorToMike[6];

MikeCubeToRubiksCube

void MikeCubeToRubiksCube(MikeCube *mikePtr, 
                                      RubiksCube *rubikPtr)
{
short f,r,c;
  theMoveP = rubikPtr->theMove;
  firstTime = 1;
  for (f=0; f<6; ++f) {
    for (r=0; r<3; ++r) {
      for (c=0; c<3; ++c) {
/* delete s,d if numbering is corrected */
        short s=r,d=c;
        rubikPtr->cubie[3*s+d][mikeToRubik[f]] = 
          mikeToRubik[ mikePtr->face[f].littleSquare[r][c]];
      }
    }
  }
  for (f=0; f<6; ++f) {
    char theColor;
    theColor = rubikFaceOrder[rubikPtr->cubie[4][f] ];
    rubikColorToMike[f] = theColor;
    mikeColorToRubik[theColor] = f;
  }
  for (f=0; f<6; ++f) 
      for (r=0; r<3; ++r)
        for (c=0; c<3; ++c) {
          char *p = &rubikPtr->cubie [3*r+c][f];
          *p = mikeColorToRubik[*p];
        }
  for (f=0; f<6; ++f) 
      for (r=0; r<3; ++r)
        for (c=0; c<3; ++c) 
          rubikPtr->origCube[3*r+c][f] = 
          rubikPtr->cubie[3*r+c][f];
//PrintCube(rubikPtr,&oldRub,' ');
}

RubiksCubeToMikeCube

void RubiksCubeToMikeCube(RubiksCube *rubikPtr, 
                                      MikeCube *mikePtr)
{
short f,r,c;
  for (f=0; f<6; ++f) {
    for (r=0; r<3; ++r) {
      for (c=0; c<3; ++c) {
        short s=r,d=c;

         mikePtr->face[f].littleSquare[r][c] =
           rubikToMike[ rubikColorToMike[ 
             rubikPtr->cubie[3*s+d][mikeToRubik[f]] ] ];
      }
    }
  }
}

SolveTopEdgesFront-Right.c

#pragma options(honor_register,assign_registers)
#include "rubik.h"
#include "transform.h"

void SolveTopEdgesFR(register RubiksCube *rub)
{

// STEP 1: Put the edge cubes in the top layer into the proper position and orientation. 
// Loop until all are correct.

  if (UF_U == U && UF_F == F) {
    /* leave edge in correct position */ ;
  } else if (UF_U == F && UF_F == U) { F2D1R1F3R3;
  } else if (UR_U == F && UR_R == U) { R3F3;
  } else if (UB_U == F && UB_B == U) { B2D3R1F3R3;
  } else if (UL_U == F && UL_L == U) { L1F1;
  } else if (UR_U == U && UR_R == F) { R2D3F2;
  } else if (UB_U == U && UB_B == F) { B2D2F2;
  } else if (UL_U == U && UL_L == F) { L2D1F2;
  } else if (RF_F == F && RF_R == U) { F3;
  } else if (RB_R == F && RB_B == U) { B3D3B1R1F3R3;
  } else if (LB_B == F && LB_L == U) { B1D2B3F2;
  } else if (LF_L == F && LF_F == U) { L1D1L3F2;
  } else if (RF_F == U && RF_R == F) { F1D1R1F3R3;
  } else if (RB_R == U && RB_B == F) { R2F3R2;
  } else if (LB_B == U && LB_L == F) { B1D3B3R1F3R3;
  } else if (LF_L == U && LF_F == F) { F1;
  } else if (DF_D == F && DF_F == U) { D1R1F3R3;
  } else if (DR_D == F && DR_R == U) { R1F3R3;
  } else if (DB_D == F && DB_B == U) { D3R1F3R3;
  } else if (DL_D == F && DL_L == U) { L3F1L1;
  } else if (DF_D == U && DF_F == F) { F2;
  } else if (DR_D == U && DR_R == F) { D3F2;
  } else if (DB_D == U && DB_B == F) { D2F2;
  } else if (DL_D == U && DL_L == F) { D1F2;
  }
//Find the top-right edge cube, and move it into the proper position.
  if (UR_U == U && UR_R == R) {
    /* leave edge in correct position */ ;
  } else if (UF_U == R && UF_F == U) { F1R1;
  } else if (UR_U == R && UR_R == U) { R2D1B1R3B3;
  } else if (UB_U == R && UB_B == U) { B3R3;
  } else if (UL_U == R && UL_L == U) { L2D3B1R3B3;
  } else if (UF_U == U && UF_F == R) { F2D1R2;
  } else if (UB_U == U && UB_B == R) { B2D3R2;
  } else if (UL_U == U && UL_L == R) { L2D2R2;
  } else if (RF_F == R && RF_R == U) { F1D1F3R2;
  } else if (RB_R == R && RB_B == U) { R3;
  } else if (LB_B == R && LB_L == U) { L3D3L1B1R3B3;
  } else if (LF_L == R && LF_F == U) { L1D2L3R2;
  } else if (RF_F == U && RF_R == R) { R1;
  } else if (RB_R == U && RB_B == R) { R1D1B1R3B3;
  } else if (LB_B == U && LB_L == R) { B2R3B2;
  } else if (LF_L == U && LF_F == R) { L1D3L3B1R3B3;
  } else if (DF_D == R && DF_F == U) { F3R1F1;
  } else if (DR_D == R && DR_R == U) { D1B1R3B3;
  } else if (DB_D == R && DB_B == U) { B1R3B3;
  } else if (DL_D == R && DL_L == U) { D3B1R3B3;
  } else if (DF_D == U && DF_F == R) { D1R2;
  } else if (DR_D == U && DR_R == R) { R2;
  } else if (DB_D == U && DB_B == R) { D3R2;
  } else if (DL_D == U && DL_L == R) { D2R2;
  }
}

SolveTopEdgesLeft-Back.c

#pragma options(honor_register,assign_registers)

#include "rubik.h"
#include "transform.h"

void SolveTopEdgesLB(register RubiksCube *rub)
{

// Find the top-back edge cube, and move it into the proper position.
  if (UB_U == U && UB_B == B)        { ;/* correct as is */
  } else if (UF_U == B && UF_F == U) { F2D3L1B3L3;
  } else if (UR_U == B && UR_R == U) { R1B1;
  } else if (UB_U == B && UB_B == U) { B2D1L1B3L3;
  } else if (UL_U == B && UL_L == U) { L3B3;
  } else if (RF_F == B && RF_R == U) { F1D2F3B2;
  } else if (RB_R == B && RB_B == U) { R1D1R3B2;
  } else if (LB_B == B && LB_L == U) { B3;
  } else if (LF_L == B && LF_F == U) { F3D3F1L1B3L3;
  } else if (DF_D == B && DF_F == U) { D3L1B3L3;
  } else if (DR_D == B && DR_R == U) { R3B1R1;
  } else if (DB_D == B && DB_B == U) { D1L1B3L3;
  } else if (DL_D == B && DL_L == U) { L1B3L3;
  } else if (UF_U == U && UF_F == B) { F2D2B2;
  } else if (UR_U == U && UR_R == B) { R2D1B2;
  } else if (UL_U == U && UL_L == B) { L2D3B2;
  } else if (RF_F == U && RF_R == B) { F1D3F3L1B3L3;
  } else if (RB_R == U && RB_B == B) { B1;
  } else if (LB_B == U && LB_L == B) { B1D1L1B3L3;
  } else if (LF_L == U && LF_F == B) { L2B3L2;
  } else if (DF_D == U && DF_F == B) { D2B2;
  } else if (DR_D == U && DR_R == B) { D1B2;
  } else if (DB_D == U && DB_B == B) { B2;
  } else if (DL_D == U && DL_L == B) { D3B2;
  }

// Find the top-left edge cube, and move it into the proper position.
  if (UL_U == U && UL_L == L)        {; /* correct as is */
  } else if (UF_U == L && UF_F == U) { F3L3;
  } else if (UR_U == L && UR_R == U) { R2D3F1L3F3;
  } else if (UB_U == L && UB_B == U) { B1L1;
  } else if (UL_U == L && UL_L == U) { L2D1F1L3F3;
  } else if (UF_U == U && UF_F == L) { F2D3L2;
  } else if (UR_U == U && UR_R == L) { R2D2L2;
  } else if (UB_U == U && UB_B == L) { B2D1L2;
  } else if (RF_F == L && RF_R == U) { R3D3R1F1L3F3;
  } else if (RB_R == L && RB_B == U) { R1D2R3L2;
  } else if (LB_B == L && LB_L == U) { B1D1B3L2;
  } else if (LF_L == L && LF_F == U) { L3;
  } else if (RF_F == U && RF_R == L) { F2L3F2;
  } else if (RB_R == U && RB_B == L) { R1D3R3F1L3F3;
  } else if (LB_B == U && LB_L == L) { L1;
  } else if (LF_L == U && LF_F == L) { L1D1F1L3F3;
  } else if (DF_D == L && DF_F == U) { F1L3F3;
  } else if (DR_D == L && DR_R == U) { D3F1L3F3;
  } else if (DB_D == L && DB_B == U) { B3L1B1;
  } else if (DL_D == L && DL_L == U) { D1F1L3F3;
  } else if (DF_D == U && DF_F == L) { D3L2;
  } else if (DR_D == U && DR_R == L) { D2L2;
  } else if (DB_D == U && DB_B == L) { D1L2;
  } else if (DL_D == U && DL_L == L) { L2;
  }
}

SolveTopCorners

#pragma options(honor_register,assign_registers)
#include "rubik.h"
#include "transform.h"

Boolean SolveTopCorners(register RubiksCube *rub)
{
short loopCount;

// STEP 2:  Put the corner cubes in the top layer into the proper position and
// orientation.  Loop until all are correct.

  loopCount=0;
  do {
    if (++loopCount>8) return false;
    if (DRF_F == U) {
      if (DRF_R == F) {
        if (DRF_D == R) {        goto URF1; 
        } else if (DRF_D == L) { D3; goto ULF1; 
        }
      } else if (DRF_R == R) {
        if (DRF_D == F) {        goto URF1; 
        } else if (DRF_D == B) { D1; goto URB1; 
        }
      } else if (DRF_R == B) {
        if (DRF_D == R) {        D1; goto URB1;
        } else if (DRF_D == L) { D2; goto ULB1;
        }
      } else if (DRF_R == L) {
        if (DRF_D == F) {        D3; goto ULF1;
        } else if (DRF_D == B) { D2; goto ULB1;
        }
      }
    } else if (DRF_R == U) {
      if (DRF_F == F) {
        if (DRF_D == R) {        goto URF1; 
        } else if (DRF_D == L) { D3; goto ULF1; 
        }
      } else if (DRF_F == R) {
        if (DRF_D == F) {        goto URF1; 
        } else if (DRF_D == B) { D1; goto URB1; 
        }
      } else if (DRF_F == B) {
        if (DRF_D == R) {        D1; goto URB1;
        } else if (DRF_D == L) { D2; goto ULB1;
        }
      } else if (DRF_F == L) {
        if (DRF_D == F) {        D3; goto ULF1;
        } else if (DRF_D == B) { D2; goto ULB1;
        }
      }
    } else if (DRF_D == U) {
      if (DRF_F == F) {
        if (DRF_R == R) {        goto URF1; 
        } else if (DRF_R == L) { D3; goto ULF1; 
        }
      } else if (DRF_F == R) {
        if (DRF_R == F) {        goto URF1; 
        } else if (DRF_R == B) { D1; goto URB1; 
        }
      } else if (DRF_F == B) {
        if (DRF_R == R) {        D1; goto URB1;
        } else if (DRF_R == L) { D2; goto ULB1;
        }
      } else if (DRF_F == L) {
        if (DRF_R == F) {        D3; goto ULF1;
        } else if (DRF_R == B) { D2; goto ULB1;
        }
      }
    }
    goto corner2;
URF1: if (DRF_F == U)        { F1D1F3;
      } else if (DRF_R == U) { R3D3R1;
      } else if (DRF_D == U) { R3D1R1D2R3D3R1;
      } 
      goto corner2;
URB1: if (DRB_R == U)        { R1D1R3;
      } else if (DRB_B == U) { B3D3B1;
      } else if (DRB_D == U) { B3D1B1D2B3D3B1;
      } 
      goto corner2;
ULB1: if (DLB_B == U)        { B1D1B3;
      } else if (DLB_L == U) { L3D3L1;
      } else if (DLB_D == U) { L3D1L1D2L3D3L1;
      }
      goto corner2;
ULF1: if (DLF_L == U)        { L1D1L3;
      } else if (DLF_F == U) { F3D3F1;
      } else if (DLF_D == U) { F3D1F1D2F3D3F1;
      } 
corner2: ;

    if (DRB_R == U) {
      if (DRB_B == F) {
        if (DRB_D == R) {        D3; goto URF2; 
        } else if (DRB_D == L) { D2; goto ULF2; 
        }
      } else if (DRB_B == R) {
        if (DRB_D == F) {        D3; goto URF2; 
        } else if (DRB_D == B) { goto URB2; 
        }
      } else if (DRB_B == B) {
        if (DRB_D == R) {        goto URB2;
        } else if (DRB_D == L) { D1; goto ULB2;
        }
      } else if (DRB_B == L) {
        if (DRB_D == F) {        D2; goto ULF2;
        } else if (DRB_D == B) { D1; goto ULB2;
        }
      }
    } else if (DRB_B == U) {
      if (DRB_R == F) {
        if (DRB_D == R) {        D3; goto URF2; 
        } else if (DRB_D == L) { D2; goto ULF2; 
        }
      } else if (DRB_R == R) {
        if (DRB_D == F) {        D3; goto URF2; 
        } else if (DRB_D == B) { goto URB2; 
        }
      } else if (DRB_R == B) {
        if (DRB_D == R) {        goto URB2;
        } else if (DRB_D == L) { D1; goto ULB2;
        }
      } else if (DRB_R == L) {
        if (DRB_D == F) {        D2; goto ULF2;
        } else if (DRB_D == B) { D1; goto ULB2;
        }
      }
    } else if (DRB_D == U) {
      if (DRB_R == F) {
        if (DRB_B == R) {        D3; goto URF2; 
        } else if (DRB_B == L) { D2; goto ULF2; 
        }
      } else if (DRB_R == R) {
        if (DRB_B == F) {        D3; goto URF2; 
        } else if (DRB_B == B) { goto URB2; 
        }
      } else if (DRB_R == B) {
        if (DRB_B == R) {        goto URB2;
        } else if (DRB_B == L) { D1; goto ULB2;
        }
      } else if (DRB_R == L) {
        if (DRB_B == F) {        D2; goto ULF2;
        } else if (DRB_B == B) { D1; goto ULB2;
        }
      }
    }
    goto corner3;
URF2: if (DRF_F == U)        { F1D1F3;
      } else if (DRF_R == U) { R3D3R1;
      } else if (DRF_D == U) { R3D1R1D2R3D3R1;
      } 
      goto corner3;
URB2: if (DRB_R == U)        { R1D1R3;
      } else if (DRB_B == U) { B3D3B1;
      } else if (DRB_D == U) { B3D1B1D2B3D3B1;
      } 
      goto corner3;
ULB2: if (DLB_B == U)        { B1D1B3;
      } else if (DLB_L == U) { L3D3L1;
      } else if (DLB_D == U) { L3D1L1D2L3D3L1;
      }
      goto corner3;
ULF2: if (DLF_L == U)        { L1D1L3;
      } else if (DLF_F == U) { F3D3F1;
      } else if (DLF_D == U) { F3D1F1D2F3D3F1;
      } 
corner3: ;
    if (DLB_B == U) {
      if (DLB_L == F) {
        if (DLB_D == R) {        D2; goto URF3; 
        } else if (DLB_D == L) { D1; goto ULF3; 
        }
      } else if (DLB_L == R) {
        if (DLB_D == F) {        D2; goto URF3; 
        } else if (DLB_D == B) { D3; goto URB3; 
        }
      } else if (DLB_L == B) {
        if (DLB_D == R) {        D3; goto URB3;
        } else if (DLB_D == L) { goto ULB3;
        }
      } else if (DLB_L == L) {
        if (DLB_D == F) {        D1; goto ULF3;
        } else if (DLB_D == B) { goto ULB3;
        }
      }
    } else if (DLB_L == U) {
      if (DLB_B == F) {
        if (DLB_D == R) {        D2; goto URF3; 
        } else if (DLB_D == L) { D1; goto ULF3; 
        }
      } else if (DLB_B == R) {
       if (DLB_D == F) {         D2; goto URF3; 
        } else if (DLB_D == B) { D3; goto URB3; 
        }
      } else if (DLB_B == B) {
        if (DLB_D == R) {        D3; goto URB3;
        } else if (DLB_D == L) { goto ULB3;
        }
      } else if (DLB_B == L) {
        if (DLB_D == F) {        D1; goto ULF3;
        } else if (DLB_D == B) { goto ULB3;
        }
      }
    } else if (DLB_D == U) {
      if (DLB_B == F) {
        if (DLB_L == R) {        D2; goto URF3; 
        } else if (DLB_L == L) { D1; goto ULF3; 
        }
      } else if (DLB_B == R) {
        if (DLB_L == F) {        D2; goto URF3; 
        } else if (DLB_L == B) { D3; goto URB3; 
        }
      } else if (DLB_B == B) {
        if (DLB_L == R) {        D3; goto URB3;
        } else if (DLB_L == L) { goto ULB3;
        }
      } else if (DLB_B == L) {
        if (DLB_L == F) {        D1; goto ULF3;
        } else if (DLB_L == B) { goto ULB3;
        }
      }
    }
    goto corner4;
URF3: if (DRF_F == U)        { F1D1F3;
      } else if (DRF_R == U) { R3D3R1;
      } else if (DRF_D == U) { R3D1R1D2R3D3R1;
      } 
      goto corner4;
URB3: if (DRB_R == U)        { R1D1R3;
      } else if (DRB_B == U) { B3D3B1;
      } else if (DRB_D == U) { B3D1B1D2B3D3B1;
      } 
      goto corner4;
ULB3: if (DLB_B == U)        { B1D1B3;
      } else if (DLB_L == U) { L3D3L1;
      } else if (DLB_D == U) { L3D1L1D2L3D3L1;
      }
      goto corner4;
ULF3: if (DLF_L == U)        { L1D1L3;
      } else if (DLF_F == U) { F3D3F1;
      } else if (DLF_D == U) { F3D1F1D2F3D3F1;
      } 
corner4: ;
    if (DLF_L == U) {
      if (DLF_F == F) {
        if (DLF_D == R) {        D1; goto URF4; 
        } else if (DLF_D == L) { goto ULF4; 
        }
      } else if (DLF_F == R) {
        if (DLF_D == F) {        D1; goto URF4; 
        } else if (DLF_D == B) { D2; goto URB4; 
        }
      } else if (DLF_F == B) {
        if (DLF_D == R) {        D2; goto URB4;
        } else if (DLF_D == L) { D3; goto ULB4;
        }
      } else if (DLF_F == L) {
        if (DLF_D == F) {        goto ULF4;
        } else if (DLF_D == B) { D3; goto ULB4;
        }
      }
    } else if (DLF_F == U) {
      if (DLF_L == F) {
        if (DLF_D == R) {        D1; goto URF4; 
        } else if (DLF_D == L) { goto ULF4; 
        }
      } else if (DLF_L == R) {
        if (DLF_D == F) {        D1; goto URF4; 
        } else if (DLF_D == B) { D2; goto URB4; 
        }
      } else if (DLF_L == B) {
        if (DLF_D == R) {        D2; goto URB4;
        } else if (DLF_D == L) { D3; goto ULB4;
        }
      } else if (DLF_L == L) {
        if (DLF_D == F) {        goto ULF4;
        } else if (DLF_D == B) { D3; goto ULB4;
        }
      }
    } else if (DLF_D == U) {
      if (DLF_L == F) {
        if (DLF_F == R) {        D1; goto URF4; 
        } else if (DLF_F == L) { goto ULF4; 
        }
      } else if (DLF_L == R) {
        if (DLF_F == F) {        D1; goto URF4; 
        } else if (DLF_F == B) { D2;  goto URB4; 
        }
      } else if (DLF_L == B) {
        if (DLF_F == R) {        D2; goto URB4;
        } else if (DLF_F == L) { D3; goto ULB4;
        }
      } else if (DLF_L == L) {
        if (DLF_F == F) {        goto ULF4;
        } else if (DLF_F == B) { D3; goto ULB4;
        }
      }
    }
    goto cornerDone;
URF4: if (DRF_F == U)        { F1D1F3;
      } else if (DRF_R == U) { R3D3R1;
      } else if (DRF_D == U) { R3D1R1D2R3D3R1;
      } 
      goto cornerDone;
URB4: if (DRB_R == U)        { R1D1R3;
      } else if (DRB_B == U) { B3D3B1;
      } else if (DRB_D == U) { B3D1B1D2B3D3B1;
      } 
      goto cornerDone;
ULB4: if (DLB_B == U)        { B1D1B3;
      } else if (DLB_L == U) { L3D3L1;
      } else if (DLB_D == U) { L3D1L1D2L3D3L1;
      }
      goto cornerDone;
ULF4: if (DLF_L == U)        { L1D1L3;
      } else if (DLF_F == U) { F3D3F1;
      } else if (DLF_D == U) { F3D1F1D2F3D3F1;
      } 
cornerDone: ;
//Exit if all 4 corner cubes in the top row are in the correct position and orientation.
    if (ULF_U==U && URF_U==U && ULB_U==U && URB_U==U &&
        ULF_F==F && URF_F==F && URF_R==R && URB_R==R &&
        ULB_B==B && URB_B==B && ULF_L==L && ULB_L==L)
          break;
//Move an incorrectly oriented corner cube in the top row down into the bottom row
    if        ((URF_U == U || URF_F == U || URF_R == U) &&
               (URF_U != U || URF_F != F || URF_R != R)) {
          R3D1R1;
    } else if ((URB_U == U || URB_R == U || URB_B == U) &&
               (URB_U != U || URB_R != R || URB_B != B)) {
          B3D1B1;
    } else if ((ULB_U == U || ULB_B == U || ULB_L == U) &&
               (ULB_U != U || ULB_B != B || ULB_L != L)) {
          L3D1L1;
    } else if ((ULF_U == U || ULF_L == U || ULF_F == U) &&
               (ULF_U != U || ULF_L != L || ULF_F != F)) {
          F3D1F1;
    }
  } while (true);
  return (true);
}

SolveMiddleLayer.c

#pragma options(honor_register,assign_registers)
#include "rubik.h"
#include "transform.h"

// Moves to transfer a cube to the middle face.

/*      FDDLDlDDf  Up face matches Left center */
#define FDDLDlDDf     F1;D2;L1;D1;L3;D2;F3;
#define RDDFDfDDr     R1;D2;F1;D1;F3;D2;R3;
#define BDDRDrDDb     B1;D2;R1;D1;R3;D2;B3;
#define LDDBDbDDl     L1;D2;B1;D1;B3;D2;L3;

Boolean  SolveMiddleLayer(register RubiksCube *rub)
{
short loopCount;
  loopCount=0;

// STEP 3:  Put the (edge) cubes in the middle layer into the proper position and 
// orientation.  Loop until all are correct.

  do {
    if (++loopCount > 24) return false;
    if (DF_F != D && DF_D != D) { /* DF in wrong position*/
      if (DF_F == F && DF_D == R)        { D3F1D2L1D1L3D2F3;
      } else if (DF_F == R && DF_D == F) { F1D2L1D1L3D2F3;
      } else if (DF_F == R && DF_D == B) { R1D2F1D1F3D2R3;
      } else if (DF_F == B && DF_D == R) { D1R1D2F1D1F3D2R3;
      } else if (DF_F == B && DF_D == L) { D1B1D2R1D1R3D2B3;
      } else if (DF_F == L && DF_D == B) { D2B1D2R1D1R3D2B3;
      } else if (DF_F == L && DF_D == F) { D2L1D2B1D1B3D2L3;
      } else if (DF_F == F && DF_D == L) { D3L1D2B1D1B3D2L3;
      }
      continue;
    } else if (DR_R != D && DR_D != D) {/* DR in wrong pos*/
      if (DR_R == F && DR_D == R)        { D2F1D2L1D1L3D2F3;
      } else if (DR_R == R && DR_D == F) { D3F1D2L1D3L3D2F3;
      } else if (DR_R == R && DR_D == B) { D3R1D2F1D1F3D2R3;
      } else if (DR_R == B && DR_D == R) { R1D2F1D3F3D2R3;
      } else if (DR_R == B && DR_D == L) { B1D2R1D1R3D2B3;
      } else if (DR_R == L && DR_D == B) { D1B1D2R1D3R3D2B3;
      } else if (DR_R == L && DR_D == F) { D1L1D2B1D1B3D2L3;
      } else if (DR_R == F && DR_D == L) { D2L1D2B1D3B3D2L3;
      }
      continue;
    } else if (DB_B != D && DB_D != D) {/* DB in wrong pos*/
      if (DB_B == F && DB_D == R)        { D1F1D2L1D1L3D2F3;
      } else if (DB_B == R && DB_D == F) { D2F1D2L1D3L3D2F3;
      } else if (DB_B == R && DB_D == B) { D2R1D2F1D1F3D2R3;
      } else if (DB_B == B && DB_D == R) { D3R1D2F1D3F3D2R3;
      } else if (DB_B == B && DB_D == L) { D3B1D2R1D1R3D2B3;
      } else if (DB_B == L && DB_D == B) { B1D2R1D3R3D2B3;
      } else if (DB_B == L && DB_D == F) { L1D2B1D1B3D2L3;
      } else if (DB_B == F && DB_D == L) { D1L1D2B1D3B3D2L3;
      }
      continue;
    } else if (DL_L != D && DL_D != D) {/* DL in wrong pos*/
      if (DL_L == F && DL_D == R)        { F1D2L1D1L3D2F3;
      } else if (DL_L == R && DL_D == F) { D1F1D2L1D3L3D2F3;
      } else if (DL_L == R && DL_D == B) { D1R1D2F1D1F3D2R3;
      } else if (DL_L == B && DL_D == R) { D2R1D2F1D3F3D2R3;
      } else if (DL_L == B && DL_D == L) { D2B1D2R1D1R3D2B3;
      } else if (DL_L == L && DL_D == B) { D3B1D2R1D3R3D2B3;
      } else if (DL_L == L && DL_D == F) { D3L1D2B1D1B3D2L3;
      } else if (DL_L == F && DL_D == L) { L1D2B1D3B3D2L3;
      }
      continue;
    }
//Exit if all edge cubes in the middle layer are in the correct position and orientation.
    else if (LF_F == F && RF_F == F &&
             RF_R == R && RB_R == R &&
             LB_B == B && RB_B == B &&
             LF_L == L && LB_L == L) {
      break;
    } else {
/*
All edges are not correct, but there are no edge cubes in the bottom layer that belong in the middle layer. 
 Need to move an incorrectly placed cube from the middle layer into the bottom layer, so that the next loop 
can orient it correctly.
 */
      if (RF_F != F || RF_R != R)        { F1D2L1D1L3D2F3;
      } else if (RB_R != R || RB_B != B) { R1D2F1D1F3D2R3;
      } else if (LB_B != B || LB_L != L) { B1D2R1D1R3D2B3;
      } else if (LF_L != L || LF_F != F) { L1D2B1D1B3D2L3;
      }
      continue;
    }
  } while(true);
  return (true);
}

SolveBottomCorners.c

#pragma options(honor_register,assign_registers)
#include "rubik.h"
#include "transform.h"

Boolean  SolveBottomCorners(register RubiksCube *rub)
{
short loopCount;
  
// STEP 4:  Move corner cubes in bottom layer into position  (but not necessarily the 
// correct orientation)

  if ( CornerEquals(D,L,B,D,R,B) ) {         D3;
  } else if ( CornerEquals(D,L,F,D,R,B) ) {  D2;
  } else if ( CornerEquals(D,R,F,D,R,B) ) {  D1;
  }
/*
Given that one corner (DRB) is in the correct position, move the other corners into the correct position.  There 
are (according to Taylor), 4 possibilities, clockwise rotation of the three other corners, counterclockwise 
rotation, horizontal exchange (of two), or diagonal exchange of two.
 */
  if ( CornerCorrect(D,R,F) ) {            /* DRF correct */
    if ( CornerCorrect(D,L,F) ) {          /* DLF correct */
      ;
    } else {
      R1D3L3D1R3D3L1D2;           /* Exchange DLF and DLB */
    }
  } else {
    if ( CornerCorrect(D,L,F) ) {
      D1B1D1R1D3R3B3;             /* Exchange DLB and DRF */
    } else {
      if ( CornerCorrect(D,L,B) ) {
        B1D3F3D1B3D3F1D2;         /* Exchange DLF and DRF */
      } else { 
        if ( CornerEquals(D,L,B,D,L,F) ) {
          L3D1R1D3L1D1R3D3;              /* DLF<-DLB<-DRF */
        } else {
          D1R1D3L3D1R3D3L1;              /* DLF<-DRF<-DLB */
        }
      }
    }
  }

//STEP 5:  Twist corners in bottom layer.

  loopCount=0;
  do {
    if (++loopCount > 16) return (false);
// At this point, all the corners in the bottom layer are in the correct positions, but 
// perhaps not in the correct orientation.  
    if (DLF_F == F && DRF_R == R &&
        DRB_B == B  && DLB_L == L)
      break;
/*  
Not all of the corners are in the correct orientation.  The cube has the property that the "twist" of corner cubes 
sums to zero, meaning that we have one of the following cases:
- 3 cubes needing a clockwise twist
- 2 cubes needing a clockwise twist and 2 needing a counterclockwise twist
- 1 cube needing a counterclockwise twist and 1 needing a clockwise twist
- 3 cubes needing a counterclockwise twist
The operators used in this cube solution twist one corner clockwise and one counterclockwise.
 */
    if (DLF_F == D) {  /* DLF needs a clockwise twist */
      L3U1L1F1U1F3;

 //Find a cube that needing a counterclockwise turn. 

      if (DLB_B == D) {
LabD1F1U3F3L3U3L1D3:
        D1F1U3F3L3U3L1D3;
      } else if (DRB_R == D) {
        D2F1U3F3L3U3L1D2;
      } else if (DRF_F == D) {
LabD3F1U3F3L3U3L1D1:
        D3F1U3F3L3U3L1D1;
      } else {// No counterclockwise turn is needed, so we make one arbitrarily
        if (DLB_D != D) {
            goto LabD1F1U3F3L3U3L1D3;
        } else {
            goto LabD3F1U3F3L3U3L1D1;
        }
      }
    } else if (DRF_R == D) {/*DRF needs a clockwise twist*/
      F3U1F1R1U1R3;
      if (DLF_L == D) {
LabD1R1U3R3F3U3F1D3:
        D1R1U3R3F3U3F1D3;
      } else if (DLB_B == D) {
        D2R1U3R3F3U3F1D2;
      } else if (DRB_R == D) {
LabD3R1U3R3F3U3F1D1:
        D3R1U3R3F3U3F1D1;
      } else {// No counterclockwise turn is needed, so we make one arbitrarily
        if (DLF_D != D) {
            goto LabD1R1U3R3F3U3F1D3;
        } else {
            goto LabD3R1U3R3F3U3F1D1;
        }
      }
    } else if (DRB_B == D) {/*DRB needs a clockwise twist*/
      R3U1R1B1U1B3;
      if (DRF_F == D) {
LabD1B1U3B3R3U3R1D3:
        D1B1U3B3R3U3R1D3;
      } else if (DLF_L == D) {
        D2B1U3B3R3U3R1D2;
      } else if (DLB_B == D) {
LabD3B1U3B3R3U3R1D1:
        D3B1U3B3R3U3R1D1;
      } else {// No counterclockwise turn is needed, so we make one arbitrarily
        if (DRF_D != D) {
            goto LabD1B1U3B3R3U3R1D3;
        } else {
            goto LabD3B1U3B3R3U3R1D1;
        }
      }
    } else if (DLB_L == D) {/*DLB needs a clockwise twist*/
      B3U1B1L1U1L3;
      if (DRB_R == D) {
LabD1L1U3L3B3U3B1D3:
        D1L1U3L3B3U3B1D3;
      } else if (DRF_F == D) {
        D2L1U3L3B3U3B1D2;
      } else if (DLF_L == D) {
LabD3L1U3L3B3U3B1D1:
        D3L1U3L3B3U3B1D1;
      } else {// No counterclockwise turn is needed, so we make one arbitrarily 
        if (DRB_D != D) { 
          goto LabD1L1U3L3B3U3B1D3;
        } else {          
          goto LabD3L1U3L3B3U3B1D1;
        }
      }
    } else {
// There are no corner cubes that need a clockwise twist.  So there must be 3 needing 
// a counterclockwise twist.  We twist one clockwise and one counterclockwise.

      if (DLF_F != F) {
        L3U1L1F1U1F3D1F1U3F3L3U3L1D3;
      } else {
        F3U1F1R1U1R3D1R1U3R3F3U3F1D3;
      }
    }
  } while(true);
  return (true);
}

SolveBottomEdges.c

#pragma options(honor_register,assign_registers)
#include "rubik.h"
#include "transform.h"

Boolean SolveBottomEdges(register RubiksCube *rub)
{
short loopCount;

// STEP 6:  Move edge cubes in bottom layer into position.

  if (DF_F == F || DF_D == F) {              /* FD in pos */
    if (DL_L == R || DL_D == R) {       /* BD->LD->RD->BD */
      B2D1R3L1B2R1L3D1B2;
    } else if (DR_R == L || DR_D == L) {/* BD->RD->LD->BD */
      B2D3R3L1B2R1L3D3B2;
    } 
  } else if (DL_L == L || DL_D == L) {       /* LD in pos */
    if (DB_B == F || DB_D == F) {       /* RD->BD->FD->RD */
      R2D1F3B1R2F1B3D1R2;
    } else if (DF_F == B || DF_D == B) {/* RD->FD->BD->RD */
      R2D3F3B1R2F1B3D3R2;
    }
  } else if (DR_R == R || DR_D == R) {       /* RD in pos */
    if (DF_F == B || DF_D == B) {       /* LD->FD->BD->LD */
      L2D1B3F1L2B1F3D1L2;
    } else if (DB_B == F || DB_D == F) {/* LD->BD->FD->LD */
      L2D3B3F1L2B1F3D3L2;
    }
  } else if (DB_B == B || DB_D == B) {       /* BD in pos */
    if (DR_R == L || DR_D == L) {       /* FD->RD->LD->FD */
      F2D1L3R1F2L1R3D1F2;
    } else if (DL_L == R || DL_D == R) {/* FD->LD->RD->FD */
      F2D3L3R1F2L1R3D3F2;
    }
  } else {
    /* There are no edges in their proper place. */
    if (DF_F == L || DF_D == L) {
      F1L1D1L3D3F2R3D3R1D1F1;
    } else if (DF_F == B || DF_D == B) {
      R2L2U1R2L2D2R2L2U1R2L2;
    } else if (DF_F == R || DF_D == R) {
      R1F1D1F3D3R2B3D3B1D1R1;
    }
  }

//STEP 7:  Flip edges in bottom layer.
 
  loopCount = 0;
  do {
    if (++loopCount > 24) return false;
//At this point, all the edge cubes in the bottom layer are in the correct positions, but //perhaps not in the 
correct orientation.  

//Exit if all edge cubes have the proper orientation.
    if (DF_F == F && DR_R == R &&
        DB_B == B  && DL_L == L)
      break;
// At least one edge cubes does not have the proper orientation.  The cube has the 
// property that an even number of edge cubes need to be flipped.
    if (DF_F == D) {
      if (DL_L == D) {
        F1D1U3R2D2U2L1D1L3U2D2R2U1D3F3D3;
      } else if (DB_B == D) {
        F1D1U3R2D2U2L1D2L3U2D2R2U1D3F3D2;
      } else if (DR_R == D) {
        F1D1U3R2D2U2L1D3L3U2D2R2U1D3F3D1;
      }
    } else if (DL_L == D) {
      if (DB_B == D) {
        L1D1U3F2D2U2B1D1B3U2D2F2U1D3L3D3;
      } else if (DR_R == D) {
        L1D1U3F2D2U2B1D2B3U2D2F2U1D3L3D2;
      } else if (DF_F == D) {
        L1D1U3F2D2U2B1D3B3U2D2F2U1D3L3D1;
      }
    } else if (DB_B == D) {
      if (DR_R == D) {
        B1D1U3L2D2U2R1D1R3U2D2L2U1D3B3D3;
      } if (DF_F == D) {
        B1D1U3L2D2U2R1D2R3U2D2L2U1D3B3D2;
      } else if (DL_L == D) {
        B1D1U3L2D2U2R1D3R3U2D2L2U1D3B3D1;
      }
    } else if (DR_R == D) {
      if (DF_F == D) {
        R1D1U3B2D2U2F1D1F3U2D2B2U1D3R3D3;
      } else if (DL_L == D) {
        R1D1U3B2D2U2F1D2F3U2D2B2U1D3R3D2;
      } else if (DB_B == D) {
        R1D1U3B2D2U2F1D3F3U2D2B2U1D3R3D1;
      }
    }
  } while(true);
  return (true);
}

transform.h

// F1move transforms the cube in response to a clockwise turn of the Front face.  
// F3move represents a counter-clockwise turn.  Similarly for the other faces.

#define F1move \
  Rot4(ULF_U,DLF_L,DRF_D,URF_R); \
  Rot4(ULF_L,DLF_D,DRF_R,URF_U); \
  Rot4(ULF_F,DLF_F,DRF_F,URF_F); \
  Rot4(UF_U,LF_L,DF_D,RF_R); \
  Rot4(UF_F,LF_F,DF_F,RF_F);
 and so on 

//This file contains the permutations used to transform the cube during the calculation
//of the solution during the first call to SolveRubiksCube.
#define F1 F1move; M(F);
#define F3 F3move; M(f);
#define L1 L1move; M(L);
#define L3 L3move; M(l);
#define R1 R1move; M(R);
#define R3 R3move; M(r);
#define B1 B1move; M(B);
#define B3 B3move; M(b);
#define U1 U1move; M(U);
#define U3 U3move; M(u);
#define D1 D1move; M(D);
#define D3 D3move; M(d);
#define F2 \
  Rot2(ULF_U,DRF_D); Rot2(ULF_L,DRF_R); \
  Rot2(ULF_F,DRF_F); Rot2(DLF_D,URF_U); \
  Rot2(DLF_L,URF_R); Rot2(DLF_F,URF_F); \
  Rot2(UF_U,DF_D);   Rot2(UF_F,DF_F); \
  Rot2(LF_L,RF_R);   Rot2(LF_F,RF_F); \
  M(F);M(F);
#define L2 \
  Rot2(ULF_U,DLB_D); Rot2(ULF_L,DLB_L); \
  Rot2(ULF_F,DLB_B); Rot2(DLF_D,ULB_U); \
  Rot2(DLF_L,ULB_L); Rot2(DLF_F,ULB_B); \
  Rot2(UL_U,DL_D);   Rot2(UL_L,DL_L); \
  Rot2(LF_L,LB_L);   Rot2(LF_F,LB_B); \
  M(L);M(L);
#define R2 \
  Rot2(URF_U,DRB_D); Rot2(URF_R,DRB_R); \
  Rot2(URF_F,DRB_B); Rot2(DRF_D,URB_U); \
  Rot2(DRF_R,URB_R); Rot2(DRF_F,URB_B); \
  Rot2(UR_U,DR_D);   Rot2(UR_R,DR_R); \
  Rot2(RF_R,RB_R);   Rot2(RF_F,RB_B); \
  M(R);M(R);
and so on 

Upper layer transforms
#define R3D1R1 \
  Rot4(DLF_D,DLB_D,DRF_F,URF_F); \
  Rot4(DLF_L,DLB_B,DRF_R,URF_U); \
  Rot4(DLF_F,DLB_L,DRF_D,URF_R); \
  Rot4(RF_R,DF_F,DL_L,DB_B); \
  Rot4(RF_F,DF_D,DL_D,DB_D); \
  M(r);M(D);M(R);
#define B3D1B1 \
  Rot4(DLF_D,DRB_R,URB_R,DRF_D); \
  Rot4(DLF_L,DRB_B,URB_U,DRF_F); \
  Rot4(DLF_F,DRB_D,URB_B,DRF_R); \
  Rot4(RB_R,DR_D,DF_D,DL_D); \
  Rot4(RB_B,DR_R,DF_F,DL_L); \
  M(b);M(D);M(B);
 much, much more of the same 

Middle layer transforms
#define D3F1D2L1D1L3D2F3 \
  Rot3(DLF_D,DLB_D,DRF_R); \
  Rot3(DLF_L,DLB_B,DRF_D); \
  Rot3(DLF_F,DLB_L,DRF_F); \
  Rot4(RF_R,DF_D,RF_F,DF_F); \
  Rot4(DR_D,DB_D,DR_R,DB_B); \
  M(d);M(F);M(D);M(D);M(L);M(D);M(l);M(D);M(D);M(f);
#define F1D2L1D1L3D2F3 \
  Rot4(DLF_D,DRB_D,DRF_D,DLB_B); \
  Rot4(DLF_L,DRB_R,DRF_F,DLB_L); \
  Rot4(DLF_F,DRB_B,DRF_R,DLB_D); \
  Rot4(RF_R,DL_D,DB_D,DF_F); \
  Rot4(RF_F,DL_L,DB_B,DF_D); \
  M(F);M(D);M(D);M(L);M(D);M(l);M(D);M(D);M(f);
 much more of the same 

Bottom Layer transforms
#define R1D3L3D1R3D3L1D2 \
  Rot6(DLF_D,DLB_D,DLF_F,DLB_L,DLF_L,DLB_B); \
  Rot3(DRF_D,DRF_R,DRF_F); \
  Rot3(DRB_D,DRB_B,DRB_R); \
  Rot4(DL_D,DB_D,DR_D,DF_D); \
  Rot4(DL_L,DB_B,DR_R,DF_F); \
  M(R);M(d);M(l);M(D);M(r);M(d);M(L);M(D);M(D);
#define D1B1D1R1D3R3B3 \
  Rot3(DLF_D,DLF_F,DLF_L); \
  Rot6(DRF_D,DLB_D,DRF_F,DLB_B,DRF_R,DLB_L); \
  Rot4(DL_D,DB_D,DF_F,DR_D); \
  Rot4(DL_L,DB_B,DF_D,DR_R); \
  M(D);M(B);M(D);M(R);M(d);M(r);M(b);
 much more of the same 
  
Corner Twist transforms 
#define L3U1L1F1U1F3 \
  Rot3(ULF_U,ULF_L,ULF_F); \
  Rot3(DLF_D,DLF_F,DLF_L); \
  Rot9(URF_U,URB_U,ULB_U,URF_F,URB_R,ULB_B,URF_R,URB_B, \
       ULB_L); \
  Rot5(UL_U,UF_F,UR_R,LF_L,UB_U); \
  Rot5(UL_L,UF_U,UR_U,LF_F,UB_B); \
  M(l);M(U);M(L);M(F);M(U);M(f);
#define D1F1U3F3L3U3L1D3 \
  Rot3(ULF_U,ULF_F,ULF_L); \
  Rot9(URF_U,ULB_L,URB_B,URF_R,ULB_B,URB_R,URF_F,ULB_U, \
       URB_U); \
  Rot3(DLB_D,DLB_B,DLB_L); \
  Rot5(UL_U,UB_U,LF_L,UR_R,UF_F); \
  Rot5(UL_L,UB_B,LF_F,UR_U,UF_U); \
  M(D);M(F);M(u);M(f);M(l);M(u);M(L);M(d);
 much more of the same 
  
Edge exchanges

#define F1D1U3R2D2U2L1D1L3U2D2R2U1D3F3D3 \
  Rot2(DL_D,DL_L); \
  Rot2(DF_D,DF_F); \
  M(F);M(D);M(u);M(R);M(R);M(D);M(D);M(U);M(U);M(L); \
  M(D);M(l);M(U);M(U);M(D);M(D);M(R);M(R);M(U);M(d); \
  M(f);M(d);
#define F1D1U3R2D2U2L1D2L3U2D2R2U1D3F3D2 \
  Rot2(DF_D,DF_F); \
  Rot2(DB_D,DB_B); \
  M(F);M(D);M(u);M(R);M(R);M(D);M(D);M(U);M(U);M(L); \
  M(D);M(D);M(l);M(U);M(U);M(D);M(D);M(R);M(R);M(U); \
  M(d);M(f);M(D);M(D);

 much more of the same 

[You can find the full source to Bob’s solution in our usual online sites. Please see page 2 for details - Ed stb]

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

iExplorer 4.1.10 - View and transfer fil...
iExplorer is an iPhone browser for Mac lets you view the files on your iOS device. By using a drag and drop interface, you can quickly copy files and folders between your Mac and your iPhone or... Read more
Adobe InCopy CC 2018 13.0.1.207 - Create...
InCopy CC 2018 is available as part of Adobe Creative Cloud for as little as $19.99/month (or $9.99/month if you're a previous InCopy customer). Adobe InCopy CC 2018, ideal for large team projects... Read more
Microsoft Office 2016 15.40 - Popular pr...
Microsoft Office 2016 - Unmistakably Office, designed for Mac. The new versions of Word, Excel, PowerPoint, Outlook and OneNote provide the best of both worlds for Mac users - the familiar Office... Read more
Adobe InDesign CC 2018 13.0.1.207 - Prof...
InDesign CC 2018 is available as part of Adobe Creative Cloud for as little as $19.99/month (or $9.99/month if you're a previous InDesign customer). Adobe InDesign CC 2018 is part of Creative Cloud.... Read more
Apple iOS 11.1.2 - The latest version of...
iOS 11 sets a new standard for what is already the world’s most advanced mobile operating system. It makes iPhone better than before. It makes iPad more capable than ever. And now it opens up both to... Read more
Slack 2.9.0 - Collaborative communicatio...
Slack is a collaborative communication app that simplifies real-time messaging, archiving, and search for modern working teams. Version 2.9.0: Slack now officially, and fully, supports Japanese.... Read more
iExplorer 4.1.9 - View and transfer file...
iExplorer is an iPhone browser for Mac lets you view the files on your iOS device. By using a drag and drop interface, you can quickly copy files and folders between your Mac and your iPhone or... Read more
PCalc 4.5.3 - Full-featured scientific c...
PCalc is a full-featured, scriptable scientific calculator with support for hexadecimal, octal, and binary calculations, as well as an RPN mode, programmable functions, and an extensive set of unit... Read more
iExplorer 4.1.9 - View and transfer file...
iExplorer is an iPhone browser for Mac lets you view the files on your iOS device. By using a drag and drop interface, you can quickly copy files and folders between your Mac and your iPhone or... Read more
PCalc 4.5.3 - Full-featured scientific c...
PCalc is a full-featured, scriptable scientific calculator with support for hexadecimal, octal, and binary calculations, as well as an RPN mode, programmable functions, and an extensive set of unit... Read more

Latest Forum Discussions

See All

Mighty Battles guide - how to build a so...
Mighty Battles, the latest title from Hothead Games, is set to take the App Store by storm. The game puts a welcome twist on lane battlers, adding FPS elements to spice things up a bit. You'll collect cards to put your own military unit to gether,... | Read more »
Rules of Survival guide - how to be the...
The PUBG craze makes its way to mobile, with more and more battle royale games debuting on iOS and Android. Rules of Survival joins the ranks of mobile PUBG-likes, offering a classic battle royale experiences that doesn't vary too much from its... | Read more »
The best new games we played this week -...
The weekend is upon us friends, and it's time to take a look back and reflect on all of the wonderful games we've played over the past few days. This week was jam packed with new releases. There were some big, long awaited launches, some fun... | Read more »
Lineage II: Revolution guide - tips and...
At long last, Lineage II: Revolution has now come to western shores, bring Netmarble's sweeping MMORPG to mobile devices. It's an addictive, epic experience, but some of the systems in the game can be a bit overwhelming. Here are a few tips to help... | Read more »
A Boy and His Blob (Games)
A Boy and His Blob 1.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0 (iTunes) Description: | Read more »
Fight terrible monsters and collect epic...
Released on Western markets early last month, Dragon Project, created by Japanese developer COLOPL, brings epic monster hunting action to mobile for the very first time. Collect a huge array of weapons and armor, and join up with friends to fight... | Read more »
I Am The Hero (Games)
I Am The Hero 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: I Am The Hero is a pixel art, beat 'em up, fighting game that tells the story of a "Hero" with a glorious but mysterious past.... | Read more »
Kauldron (Music)
Kauldron 1.0 Device: iOS Universal Category: Music Price: $3.99, Version: 1.0 (iTunes) Description: Kauldron is our warmest sounding, punchiest synth yet! A completely new modeling technology, combined with carefully designed... | Read more »
Lineage II: Revolution is mobile’s bigge...
NCSoft’s hit fantasy MMORPG series has just made the leap to mobile with the help of Netmarble in Lineage II: Revolution. With over 1.5 million players having already pre-registered ahead of the game’s launch, Revolution hit the app stores... | Read more »
Swing skilfully in new physics-based pla...
Sometimes it’s the most difficult of obstacles that can be the most rewarding. One game hoping to prove this is OCMO, the new tough but fair platformer from developers Team Ocmo. Primed to set every speedrunner’s pulse racing, as an otherworldly... | Read more »

Price Scanner via MacPrices.net

Best Apple iPad deals this weekend, up to $80...
Apple resellers are offering 9.7″ iPads and 10.5″ iPad Pros for up to $80 off MSRP this weekend as part of their early Holiday and Black Friday sales: Adorama is offering new 2017 9.7″ 32GB WiFi... Read more
Early Black Friday sale: Apple iMacs for up t...
B&H Photo has 27-inch iMacs in stock and on sale for up $130-$150 off MSRP including free shipping. B&H charges sales tax in NY & NJ only: – 27″ 3.8GHz iMac (MNED2LL/A): $2149 $150 off... Read more
Apple restocks refurbished Mac minis starting...
Apple has restocked Certified Refurbished Mac minis starting at $419. Apple’s one-year warranty is included with each mini, and shipping is free: – 1.4GHz Mac mini: $419 $80 off MSRP – 2.6GHz Mac... Read more
Save on 12″ MacBooks, Apple refurbished model...
Apple has Certified Refurbished 2017 12″ Retina MacBooks available for $200-$240 off the cost of new models. Apple will include a standard one-year warranty with each MacBook, and shipping is free.... Read more
Early Holiday sale: 12″ iPad Pros for up to $...
B&H Photo has 12″ iPad Pros on sale today for up to $130 off MSRP. Shipping is free, and B&H collects no sales tax outside NY & NJ: – 12″ 64GB WiFi iPad Pro: $749, save $50 – 12″ 256GB... Read more
Holiday sale prices on Apple 13″ MacBook Pros...
B&H Photo has 2017 13″ MacBook Pros in stock today and on sale for $100-$150 off MSRP, each including free shipping plus NY & NJ sales tax only: – 13-inch 2.3GHz/128GB Space Gray MacBook Pro... Read more
Sale: 13″ MacBook Airs starting at $899, $100...
B&H Photo has 2017 13″ MacBook Airs on sale today for $100 off MSRP including free shipping. B&H charges NY & NJ sales tax only: – 13″ 1.8GHz/128GB MacBook Air (MQD32LL/A): $899, $100 off... Read more
Week’s Best Deal on 13″ MacBook Pros: Apple r...
Apple has a full line of Apple Certified Refurbished 2017 13″ MacBook Pros available for $200-$300 off MSRP. A standard Apple one-year warranty is included with each MacBook, and shipping is free.... Read more
Deal: 15″ 2.6GHz MacBook Pro for $1799 w/free...
B&H Photo has clearance 2016 15″ 2.6GHz Touch Bar MacBook Pros in stock today and available for $600 off original MSRP. Shipping is free, and B&H charges NY & NJ sales tax only: – 15″ 2.... Read more
Black Friday pricing on the 1.4GHz Mac mini....
MacMall has the 1.4GHz Mac mini on sale for $399 including free shipping. Their price is $100 off MSRP (20% off), and it’s the lowest price for available for this model from any reseller. MacMall’s... Read more

Jobs Board

Product Manager - *Apple* Pay on the *Appl...
Job Summary Apple is looking for a talented product manager to drive the expansion of Apple Pay on the Apple Online Store. This position includes a unique Read more
*Apple* Pro/Consumer Apps Support Engineer -...
…exemplify AppleCare's expert technical support paired with exceptional customer service for Apple 's software apps. This person is a problem solver, who understands Read more
Partner Marketing Manager, *Apple* Pay - Ap...
Job Summary The Apple Pay partner marketing team is looking for a Marketing Manager to develop and drive US programs. The right candidate will be passionate about Read more
*Apple* Solution Consultant - Apple (United...
# Apple Solution Consultant - Rochester, MN Job Number: 113037950 Rochester, MN, Minnesota, United States Posted: 19-Sep-2017 Weekly Hours: 40.00 **Job Summary** Are Read more
Sr. Experience Producer, Today at *Apple* -...
# Sr. Experience Producer, Today at Apple Job Number: 56495251 Santa Clara Valley, California, United States Posted: 23-Jun-2017 Weekly Hours: 40.00 **Job Summary** Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.