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

Fantastical 2.3.6 - Create calendar even...
Fantastical 2 is the Mac calendar you'll actually enjoy using. Creating an event with Fantastical is quick, easy, and fun: Open Fantastical with a single click or keystroke Type in your event... Read more
Creative Kit 1.1 - $149.99
Creative Kit 2016--made exclusively for Mac users--is your ticket to the most amazing images you've ever created. With a variety of powerful tools at your fingertips, you'll not only repair and fine-... Read more
iMazing 2.2.3 - Complete iOS device mana...
iMazing (was DiskAid) is the ultimate iOS device manager with capabilities far beyond what iTunes offers. With iMazing and your iOS device (iPhone, iPad, or iPod), you can: Copy music to and from... Read more
Apple Configurator 2.4 - Configure and d...
Apple Configurator makes it easy to deploy iPad, iPhone, iPod touch, and Apple TV devices in your school or business. Use Apple Configurator to quickly configure large numbers of devices connected to... Read more
WhatRoute 2.0.18 - Geographically trace...
WhatRoute is designed to find the names of all the routers an IP packet passes through on its way from your Mac to a destination host. It also measures the round-trip time from your Mac to the router... Read more
Posterino 3.3.5 - Create posters, collag...
Posterino offers enhanced customization and flexibility including a variety of new, stylish templates featuring grids of identical or odd-sized image boxes. You can customize the size and shape of... Read more
Skim 1.4.28 - PDF reader and note-taker...
Skim is a PDF reader and note-taker for OS X. It is designed to help you read and annotate scientific papers in PDF, but is also great for viewing any PDF file. Skim includes many features and has a... Read more
Apple macOS Sierra 10.12.4 - The latest...
With Apple macOS Sierra, Siri makes its debut on Mac, with new features designed just for the desktop. Your Mac works with iCloud and your Apple devices in smart new ways, and intelligent... Read more
Apple Numbers 4.1 - Apple's spreads...
With Apple Numbers, sophisticated spreadsheets are just the start. The whole sheet is your canvas. Just add dramatic interactive charts, tables, and images that paint a revealing picture of your data... Read more
Xcode 8.3 - Integrated development envir...
Xcode includes everything developers need to create great applications for Mac, iPhone, iPad, and Apple Watch. Xcode provides developers a unified workflow for user interface design, coding, testing... Read more

Power Rangers: Legacy Wars beginner...
Rita Repulsa is back, but this time she's invading your mobile phone in Power Rangers: Legacy Wars. What looks to be a straightforward beat 'em up is actually a tough-as-nails multiplayer strategy game that requires some deft tactical maneuvering.... | Read more »
Hearthstone celebrates the upcoming Jour...
Hearthstone gets a new expansion, Journey to Un'Goro, in a little over a week, and they'll be welcoming the Year of the Mammoth, the next season, at the same time. There's a lot to be excited about, so Blizzard is celebrating in kind. Players will... | Read more »
4 smart and stylish puzzle games like Ty...
TypeShift launched a little over a week ago, offering some puzzling new challenges for word nerds equipped with an iOS device. Created by Zach Gage, the mind behind Spelltower, TypeShift boasts, like its predecessor, a sleak design and some very... | Read more »
The best deals on the App Store this wee...
Deals, deals, deals. We're all about a good bargain here on 148Apps, and luckily this was another fine week in App Store discounts. There's a big board game sale happening right now, and a few fine indies are still discounted through the weekend.... | Read more »
The best new games we played this week
It's been quite the week, but now that all of that business is out of the way, it's time to hunker down with some of the excellent games that were released over the past few days. There's a fair few to help you relax in your down time or if you're... | Read more »
Orphan Black: The Game (Games)
Orphan Black: The Game 1.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0 (iTunes) Description: Dive into a dark and twisted puzzle-adventure that retells the pivotal events of Orphan Black. | Read more »
The Elder Scrolls: Legends is now availa...
| Read more »
Ticket to Earth beginner's guide: H...
Robot Circus launched Ticket to Earth as part of the App Store's indie games event last week. If you're not quite digging the space operatics Mass Effect: Andromeda is serving up, you'll be pleased to know that there's a surprising alternative on... | Read more »
Leap to victory in Nexx Studios new plat...
You’re always a hop, skip, and a jump away from a fiery death in Temple Jump, a new platformer-cum-endless runner from Nexx Studio. It’s out now on both iOS and Android if you’re an adventurer seeking treasure in a crumbling, pixel-laden temple. | Read more »
Failbetter Games details changes coming...
Sunless Sea, Failbetter Games' dark and gloomy sea explorer, sets sail for the iPad tomorrow. Ahead of the game's launch, Failbetter took to Twitter to discuss what will be different in the mobile version of the game. Many of the changes make... | Read more »

Price Scanner via MacPrices.net

Is A New 10.5-inch iPad Still Coming In April...
There was no sign or mention of a long-rumored and much anticipated 10.5-inch iPad Pro in Apple’s product announcements last week. The exciting iPad news was release of an upgraded iPad Air with a... Read more
T-Mobile’s Premium Device Protection Now Incl...
Good news for T-Mobile customers who love their iPhones and iPads. The “Un-carrier” has become the first national wireless company to give customers AppleCare Services at zero additional cost as part... Read more
FileWave Ensures Support for Latest Apple OS...
FileWave multi-platform device management providers announced support for Apple’s release yesterday of iOS 10.3, macOS Sierra 10.12.4, and tvOS 11.2. FileWave has a history of providing zero-day... Read more
Use Apple’s Education discount to save up to...
Purchase a new Mac or iPad using Apple’s Education Store and take up to $300 off MSRP. All teachers, students, and staff of any educational institution qualify for the discount. Shipping is free: -... Read more
Apple refurbished Apple Watches available sta...
Apple is now offering Certified Refurbished Series 1 and Series 2 Apple Watches for 14-16% off MSRP, starting at $229. An Apple one-year warranty is included with each watch. Shipping is free: Series... Read more
9-inch 32GB Space Gray iPad Pro on sale for $...
B&H Photo has the 9.7″ 32GB Space Gray Apple iPad Pro on sale for $549 for a limited time. Shipping is free, and B&H charges NY sales tax only. Their price is $50 off MSRP. Read more
13-inch MacBook Airs on sale for $100-$150 of...
B&H Photo has 13″ MacBook Airs on sale for up to $150 off MSRP. Shipping is free, and B&H charges NY sales tax only: - 13″ 1.6GHz/128GB MacBook Air (MMGF2LL/A): $899 $100 off MSRP - 13″ 1.... Read more
13-inch MacBook Airs, Apple refurbished, in s...
Apple has Certified Refurbished 2016 13″ MacBook Airs available starting at $849. An Apple one-year warranty is included with each MacBook, and shipping is free: - 13″ 1.6GHz/8GB/128GB MacBook Air: $... Read more
12-inch Retina MacBooks on sale for $1199, sa...
B&H has 12″ 1.1GHz Retina MacBooks on sale for $100 off MSRP. Shipping is free, and B&H charges NY sales tax only: - 12″ 1.1GHz Space Gray Retina MacBook: $1199 $100 off MSRP - 12″ 1.1GHz... Read more
Save up to $260 with Apple refurbished 12-inc...
Apple has Certified Refurbished 2016 12″ Retina MacBooks available for $200-$260 off MSRP. Apple will include a standard one-year warranty with each MacBook, and shipping is free. The following... Read more

Jobs Board

Fulltime aan de slag als shopmanager in een h...
Ben jij helemaal gek van Apple -producten en vind je het helemaal super om fulltime shopmanager te zijn in een jonge en hippe elektronicazaak? Wil jij werken in Read more
Desktop Analyst - *Apple* Products - Montef...
…technology to improve patient care. JOB RESPONSIBILITIES: Provide day-to-day support for Apple Hardware and Software in the environment based on the team's support Read more
*Apple* Mobile Master - Best Buy (United Sta...
**493168BR** **Job Title:** Apple Mobile Master **Location Number:** 000827-Denton-Store **Job Description:** **What does a Best Buy Apple Mobile Master do?** At Read more
Fulltime aan de slag als shopmanager in een h...
Ben jij helemaal gek van Apple -producten en vind je het helemaal super om fulltime shopmanager te zijn in een jonge en hippe elektronicazaak? Wil jij werken in Read more
*Apple* Mobile Master - Best Buy (United Sta...
**492889BR** **Job Title:** Apple Mobile Master **Location Number:** 000886-Norwalk-Store **Job Description:** **What does a Best Buy Apple Mobile Master do?** Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.