TweetFollow Us on Twitter

Mar 96 Challenge
Volume Number:12
Issue Number:3
Column Tag:Programmer’s Challenge

Programmer’s Challenge

By Bob Boonstra, Westford, Massachusetts

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

Words The Reverse

Text input, of Block given a in words of order the place (in reverse) will that routine a write to is challenge the month this. Oops, what I meant to say was: This month, the Challenge is to write a routine that will reverse (in place) the order of words in a given block of input text. The prototype for the code you should write is:

pascal void ReverseTheWords(
 const char *text, /* the words you should reverse */
 const long numCharsIn    /* length of inputText in chars */
);

Specifically, ReverseTheWords should exchange the first word in the input text with the last word, the second word with the next-to-last word, etc. For the purpose of this Challenge, a word is defined as a continuous sequence of alphanumeric characters [a..zA..Z0..9]. Any nonalphanumeric characters should remain in their original positions and in their original order with respect to the new words; that is, punctuation, white space, and other characters between the first and second input words should, on output, be located between the new first and second words. As an example, ReverseTheWords would convert:

 This, however, <-is-> a (difficult) test.

into

 Test, difficult, <-a-> is (however) this.

As you can see from the example, there is one additional requirement. Your code needs to adjust the capitalization of words so that the n-th word is capitalized on output only if the n-th word was capitalized in the input text.

There are no specific restrictions on the amount of auxiliary memory you may use (within reason), so you may allocate a few buffers of size numCharsIn should you need them. Remember, however, to deallocate any memory you allocate before returning, as I will be calling your code many times.

Note that the prototype specifies the use of Pascal calling conventions. That is because this month we are conducting

A Language Experiment

Over the past months, in response to suggestions from readers, we have made a number of changes to the Challenge, including migrating to PowerPC native code and expanding to other C compilers. Now we are experimenting with some additional changes. This month, for the first time, your solution to the Challenge can be coded in C, C++, or Pascal, using your choice among the MPW, Metrowerks, or Symantec compilers for these languages. Although either 68K or PowerPC code is permitted, I will be running your code on a PowerMac 8500, so native code is obviously recommended. The environment you choose must support linking your solution with test code written in C. Along with your solution, you should specify the intended environment, compiler and compiler options, or (better yet) provide a project file or make file that will generate a stand-alone application that calls your solution from C test code.

Two Months Ago Winner

Congratulations to Jorg “jbx” Brown and Eric Gundrum for submitting the fastest entry to the Sliding Tiles Challenge. Contestants were asked to unscramble an N¥M grid of interlocking tiles, where a tile could be moved horizontally or vertically into the empty tile location. Fourteen of the 16 entries submitted worked correctly. The table below presents selected results from the timing tests, which used puzzles ranging in size from 8¥8 to 100¥300. (Two of the entries worked too slowly to complete the entire test suite.)

The most common solution technique involved solving the puzzle row-by-row from the bottom, being careful not to disturb tiles that had already been moved into their correct positions. The top two rows were solved together, starting from the right column and working left. Several solutions, including the winners’ and the even more move-efficient second-place entry by Peter Lewis, refined this by using a “greedy” algorithm that solves the bottom row and right column first, then moves to the next row and column. Since the problem involved use of a given callback routine for each move, it was important to reduce the number of tile moves. Some solutions moved tiles primarily in horizontal and vertical directions; others (including the winners’) devised operators that moved a tile diagonally in fewer moves.

Thanks to Greg Linden for sending me a reference to an article on this subject in Information Processing Letters (Oct. 1995). In that article, Ian Parberry (University of North Texas) establishes some bounds on algorithms for the n2-1 puzzle (the square version of this Challenge). The article proves that the “greedy” algorithm requires at most 5n3 moves in the worst case, and that any algorithm must make at least n3 moves (ignoring lower-order terms for both bounds). While a better algorithm may exist, Ian speculates that the lower bound could be made tighter. Interested readers can contact the author at ian@cs.unt.edu, or browse his web page at http://hercule.csci.unt.edu/ian.

Here are the times for each of the correct entries. Numbers in parentheses after a person’s name indicate that person’s cumulative point total for all previous Challenges, not including this one.

Time Time Total # of Moves

Name 20x20 100x300 Time (Millions)

Jorg Brown (10)

& Eric Gundrum 183 175730 261694 249

Peter Lewis 195 197905 294931 228

Christopher Phillips 211 200368 302774 269

Ludovic Nicolle 252 220952 337386 300

Ernst Munter (110) 159 258165 365894 295

Randy Boring 386 309630 481609 307

Cathy Saxton 264 338127 496610 299

Rishi Khan (age 16) 284 350763 506952 320

Xan Gregg (88) 296 360735 531493 299

Tom Saxton (10) 333 404155 592967 339

Miguel Cruz Picão(7) 245 652588 912267 339

John Sweeney (4) 300 875362 1223956 321

A. K. * * * *

G. L. * * * *

Top Contestants Of All Time

Here are the Top Contestants for the Programmer’s Challenges to date, including everyone who has accumulated more than 20 points. The numbers below include points awarded for this month’s entrants.

Rank Name Points Rank Name Points

1. [Name deleted] 176 11. Mallett, Jeff 44

2. Munter, Ernst 112 12. Kasparian, Raffi 42

3. Gregg, Xan 88 13. Vineyard, Jeremy 42

4. Larsson, Gustav 87 14. Lengyel, Eric 40

5. Karsh, Bill 80 15. Darrah, Dave 31

6. Stenger, Allen 65 16. Brown, Jorg 30

7. Riha, Stepan 51 17. Landry, Larry 29

8. Cutts, Kevin 50 18. Elwertowski, Tom 24

9. Goebel, James 49 19. Lee, Johnny 22

10. Nepsund, Ronald 47 20. Noll, Robert 22

There are three ways to earn points: (1) scoring in the top 5 of any Challenge, (2) being the first person to find a bug in a published winning solution or, (3) being the first person to suggest a Challenge that I use. The points you can win are:

1st place 20 points 5th place 2 points

2nd place 10 points finding bug 2 points

3rd place 7 points suggesting Challenge 2 points

4th place 4 points

Here the winning solution by Jorg and Eric:

SlidingTiles.c

Written by Jorg Brown & Eric Gundrum

Thanks also to Brad Kollmyer

typedef Boolean (*MoveProc)(
  long tileToMoveRow, long tileToMoveCol);

static MoveProc gMakeMove;
static long *gTiles, gNumCols, *gPieceRow, *gPieceCol;
static long *gBlankSquare; // initialized by SolveTiles, updated by BlankXXX()

#define gBlankRow pieceRow[0]
#define gBlankCol pieceCol[0]

BlankUp
static void BlankUp() { // move the BLANK SQUARE up
   long   tile, *oldBlankSquare, *newBlankSquare;
   long   *pieceRow = gPieceRow;
   long   *pieceCol = gPieceCol;

   oldBlankSquare = gBlankSquare;
   gBlankSquare = newBlankSquare = oldBlankSquare - gNumCols;
   tile = *newBlankSquare;
   pieceRow[tile] = gBlankRow--;
   gMakeMove(gBlankRow, gBlankCol);
   *oldBlankSquare = tile;
   *newBlankSquare = 0;
}

BlankDown
static void BlankDown() { // move the BLANK SQUARE down
   long   tile, *oldBlankSquare, *newBlankSquare;
   long   *pieceRow = gPieceRow;
   long   *pieceCol = gPieceCol;

   oldBlankSquare = gBlankSquare;
   gBlankSquare = newBlankSquare = oldBlankSquare + gNumCols;
   tile = *newBlankSquare;
   pieceRow[tile] = gBlankRow++;
   gMakeMove(gBlankRow, gBlankCol);
   *oldBlankSquare = tile;
   *newBlankSquare = 0;
}

MoveBlankToRow
static void MoveBlankToRow(long destRow) {
   long   tile, *oldBlankSquare, *newBlankSquare;
   long   *pieceRow = gPieceRow;
   long   *pieceCol = gPieceCol;
   long   blankRow = gBlankRow;
   long   rowInc, BlankSquareInc;

   if (blankRow < destRow) { // move DOWN
      rowInc = 1;
      BlankSquareInc = gNumCols;
   } else if (blankRow > destRow) { // move UP
      rowInc = -1;
      BlankSquareInc = -gNumCols;
   } else return;

   oldBlankSquare = gBlankSquare;
   do {
      newBlankSquare = oldBlankSquare + BlankSquareInc;
      tile = *newBlankSquare;
      pieceRow[tile] = blankRow;
      blankRow += rowInc;
      gMakeMove(blankRow, gBlankCol);
      *oldBlankSquare = tile;
      *newBlankSquare = 0;
      oldBlankSquare = newBlankSquare;
   } while (blankRow != destRow);
   gBlankSquare = newBlankSquare;
   gBlankRow = blankRow;
}

BlankLeft
static void BlankLeft() { // move the BLANK SQUARE left
   long   tile, *oldBlankSquare, *newBlankSquare;
   long   *pieceRow = gPieceRow;
   long   *pieceCol = gPieceCol;

   oldBlankSquare = gBlankSquare;
   gBlankSquare = newBlankSquare = oldBlankSquare - 1;
   tile = *newBlankSquare;
   pieceCol[tile] = gBlankCol--;
   gMakeMove(gBlankRow, gBlankCol);
   *oldBlankSquare = tile;
   *newBlankSquare = 0;
}


BlankRight
static void BlankRight() { // move the BLANK SQUARE right
   long   tile, *oldBlankSquare, *newBlankSquare;
   long   *pieceRow = gPieceRow;
   long   *pieceCol = gPieceCol;

   oldBlankSquare = gBlankSquare;
   gBlankSquare = newBlankSquare = oldBlankSquare + 1;
   tile = *newBlankSquare;
   pieceCol[tile] = gBlankCol++;
   gMakeMove(gBlankRow, gBlankCol);
   *oldBlankSquare = tile;
   *newBlankSquare = 0;
}

MoveBlankToCol
static void MoveBlankToCol(long destCol) {
   long   tile, *oldBlankSquare, *newBlankSquare;
   long   *pieceRow = gPieceRow;
   long   *pieceCol = gPieceCol;
   long   blankCol = gBlankCol;
   long   inc;

   if (blankCol < destCol) { // move RIGHT
      inc = 1;
   } else if (blankCol > destCol) { // move LEFT
      inc = -1;
   } else return;

   oldBlankSquare = gBlankSquare;
   do {
      newBlankSquare = oldBlankSquare + inc;
      tile = *newBlankSquare;
      pieceCol[tile] = blankCol;
      blankCol += inc;
      gMakeMove(gBlankRow, blankCol);
      *oldBlankSquare = tile;
      *newBlankSquare = 0;
      oldBlankSquare = newBlankSquare;
   } while (blankCol != destCol);
   gBlankSquare = newBlankSquare;
   gBlankCol = blankCol;
}

MoveAPiece

static void MoveAPiece(long piece, long destRow, long destCol, 
 long nextPiece) {
   long   sourceRow, sourceCol;
   long   *pieceRow = gPieceRow;
   long   *pieceCol = gPieceCol;
   long   nextRow = gNumCols;

   sourceRow = pieceRow[piece];
   sourceCol = pieceCol[piece];

   if (sourceRow >= destRow) { 
      // in this case, we have to move the tile up (or directly right) to get to its destination
      if (sourceRow == destRow) {
         if (sourceCol == destCol) return;

         // simplify: move the blank so that it is not to the right of the target
         if (gBlankCol > destCol) {
            MoveBlankToCol(destCol);
         }

         // move the blank to the left of the source, possibly moving the source
         // to the right at the same time.
         if (gBlankRow != destRow) {
            if (sourceCol == destCol-1 && gBlankRow > destRow) {
               MoveBlankToCol(sourceCol - 1);
               MoveBlankToRow(sourceRow - 1);
               BlankRight(); BlankRight();
               BlankDown();  BlankLeft();
               return; // all done
            } else {
               MoveBlankToCol(sourceCol + 1);
               MoveBlankToRow(sourceRow);
               BlankLeft();
               sourceCol++;
            }
         } else {
            if (gBlankCol < sourceCol) {
               MoveBlankToCol(sourceCol - 1);
            } else {
               MoveBlankToCol(sourceCol);
               sourceCol++;
            }
         }
         
WereOnTheSameRowNow:
         // at this point, the blank is to the left of the source,
         // and the puzzle might very well be done already.
         while (sourceCol != destCol) {
            if (nextPiece == piece - 1) { // into a row?
               if (gBlankCol != 0 && 
                     pieceCol[nextPiece]-pieceRow[nextPiece] <= 
                     gBlankCol-gBlankRow) {
                  MoveAPiece(nextPiece, gBlankRow, gBlankCol, 
                               nextPiece - 1);
               }
               if (gBlankRow == destRow) 
                 while ((gBlankSquare[-1] == gBlankSquare[1] - 1) 
                        && gBlankCol != 0) {
                  BlankLeft();
               }
            }
            if (gBlankRow == destRow) BlankUp();
            do {
               BlankRight();
            } while (gBlankCol <= sourceCol);
            BlankDown();  BlankLeft();  sourceCol++;
         }
         return;
      }
      // simplify: move the blank so that it is to the left of the target
      if (gBlankCol >= destCol) {
         MoveBlankToCol(destCol - 1);
      }
      // simplify: move the blank so that it is not above the target.
      if (gBlankRow < destRow) MoveBlankToRow(destRow);

again1:   // simplify: if the blank is below the source, move it so it’s not.
      sourceRow = pieceRow[piece];
      sourceCol = pieceCol[piece];
      if (gBlankRow >= sourceRow) {
         // if the blank is in the same column, move it away first.
         if (gBlankCol == sourceCol) {
            if (gBlankCol == destCol - 1) {
               BlankLeft();
            } else {
               BlankRight();
            }
         }
         // now that they're in different columns, move the blank so it’s not below
         MoveBlankToRow(sourceRow);
      }
      // simplify: if the blank is on the same row, and to the left, move up.
      if (gBlankRow == sourceRow && gBlankCol < sourceCol) {
         BlankUp();
      }
      // simplify: if the blank is to the left, move it to the same column.
      if (gBlankCol < sourceCol) {
         MoveBlankToCol(sourceCol);
      }
      // simplify: if the blank is to the upper right, move it to the left and down.
      if (gBlankRow < sourceRow) {
         if (gBlankCol > sourceCol) {
            MoveBlankToCol(sourceCol);
         }
         if (gBlankRow < sourceRow - 1) {
            MoveBlankToRow(sourceRow - 1);
         }
      }
      // if the blank is off to the right, move it next to the source.
      while (gBlankCol > sourceCol + 1) {
         MoveBlankToCol(sourceCol + 1);
      }
      // at this point, the blank should be either just above or just right of the piece.
      if (gBlankCol == sourceCol) {
         if (gBlankRow != sourceRow - 1) Debugger();
      } else {
         if (gBlankRow != sourceRow) Debugger();
         if (gBlankCol != sourceCol + 1) Debugger();
         BlankLeft();  BlankUp();    BlankRight();
      }
      BlankDown();
      sourceRow = pieceRow[piece];
      sourceCol = pieceCol[piece];
      if (sourceRow != destRow) goto again1;
      if (gBlankCol != destCol - 1) {
         BlankRight(); BlankUp();    BlankLeft();
         while (pieceCol[piece] != destCol) {
            BlankUp();    BlankRight(); BlankRight();
            BlankDown();  BlankLeft();
         }
         return; // DONE!!!!
      }
      BlankLeft();  BlankUp();    BlankUp();    BlankRight(); 
      BlankRight(); BlankDown();  BlankLeft();
      return; // DONE!!!!
   }

   // at this point, we know that source is above our destination.
   if (sourceCol >= destCol) { 
      // in this case, we have to move the tile left (or directly down) to get to its destination
      if (sourceCol == destCol) {

         // simplify: move the blank so that it is not below the target
         if (gBlankRow > destRow) {
            MoveBlankToRow(destRow);
         }

         // move the blank above the source, possibly moving the source
         // down at the same time.
         if (gBlankCol != destCol) {
            if (sourceRow == destRow-1 && gBlankCol > destCol) {
               MoveBlankToRow(sourceRow - 1);
               MoveBlankToCol(sourceCol - 1);
               BlankDown();  BlankDown();
               BlankRight(); BlankUp();
               return; // all done
            } else {
               MoveBlankToRow(sourceRow + 1);
               MoveBlankToCol(sourceCol);
               BlankUp();
               sourceRow++;
            }
         } else {
            if (gBlankRow < sourceRow) {
               MoveBlankToRow(sourceRow - 1);
            } else {
               MoveBlankToRow(sourceRow);
               sourceRow++;
            }
         }
         
WereInTheSameColumnNow:
         // at this point, the blank is on top of the source,
         // and the puzzle might very well be done already.
         while (sourceRow != destRow) {
            if (nextPiece == piece - nextRow) { // into a column?
               if (gBlankRow != 0 && 
                   pieceCol[nextPiece]-pieceRow[nextPiece] >= 
                     gBlankCol-gBlankRow) {
                  MoveAPiece(nextPiece, gBlankRow, gBlankCol, 
                               nextPiece - nextRow);
               }
               if (gBlankCol == destCol) 
                 while ((gBlankSquare[-nextRow] == 
                         gBlankSquare[nextRow] - 1) && 
                        gBlankRow != 0) {
                  BlankUp();
               }
            }
            if (gBlankCol == destCol) BlankLeft();
            do {
               BlankDown();
            } while (gBlankRow <= sourceRow);
            BlankRight(); BlankUp();    sourceRow++;
         }
         return;
      }
      // simplify: move the blank so that it is to the up of the target
      if (gBlankRow >= destRow) {
         MoveBlankToRow(destRow - 1);
      }
      // simplify: move the blank so that it is not to the left of the target.
      if (gBlankCol < destCol) MoveBlankToCol(destCol);

again2:   // simplify: if the blank is to the right of the source, move it so it’s not.
      sourceRow = pieceRow[piece];
      sourceCol = pieceCol[piece];
      if (gBlankCol >= sourceCol) {
         // if the blank is in the same row, move it away first.
         if (gBlankRow == sourceRow) {
            if (gBlankRow == destRow - 1) {
               BlankUp();
            } else {
               BlankDown();
            }
         }
         // now that they’re in different rows, move the blank so it’s not to the right of
         MoveBlankToCol(sourceCol);
      }
      // simplify: if the blank is on the same column, and to the up, move left.
      if (gBlankCol == sourceCol && gBlankRow < sourceRow) {
         BlankLeft();
      }
      // simplify: if the blank is to the up, move it to the same row.
      if (gBlankRow < sourceRow) {
         MoveBlankToRow(sourceRow);
      }
      // simplify: if the blank is to the lower left, move it to the right and up.
      if (gBlankCol < sourceCol) {
         if (gBlankRow > sourceRow) {
            MoveBlankToRow(sourceRow);
         }
         if (gBlankCol < sourceCol - 1) {
            MoveBlankToCol(sourceCol - 1);
         }
      }
      // if the blank is off to the down, move it next to the source.
      while (gBlankRow > sourceRow + 1) {
         MoveBlankToRow(sourceRow + 1);
      }
      // at this point, the blank should be either just below or just to the left of the piece.
      if (gBlankRow == sourceRow) {
         if (gBlankCol != sourceCol - 1) Debugger();
      } else {
         if (gBlankCol != sourceCol) Debugger();
         if (gBlankRow != sourceRow + 1) Debugger();
         BlankUp();    BlankLeft();  BlankDown();
      }
      BlankRight();
      sourceRow = pieceRow[piece];
      sourceCol = pieceCol[piece];
      if (sourceCol != destCol) goto again2;
      if (gBlankRow != destRow - 1) {
         BlankDown();  BlankLeft();  BlankUp();
         while (pieceRow[piece] != destRow) {
            BlankLeft();  BlankDown();
            BlankDown();  BlankRight(); BlankUp();
         }
         return; // DONE!!!!
      }
      BlankUp();    BlankLeft();  BlankLeft();  BlankDown();
      BlankDown();  BlankRight(); BlankUp();
      return; // DONE!!!!
   }

   // at this point, we know that we are above and to the left of our destination.

   if (destCol - sourceCol == destRow - sourceRow) {
      // we’re on the diagonal.
      if (gBlankCol >= sourceCol) {
         if (gBlankRow <= sourceRow) goto MoveSrcRightFirst;
      }
      if (gBlankRow >= sourceRow) {
         if (gBlankCol <= sourceCol) goto MoveSrcDownFirst;
      }
      if (gPieceRow[nextPiece] - gPieceCol[nextPiece] > 
          destRow - destCol) {
         // relative to the destination, the next piece is to the lower left.
         // this means we want the blank to end up to the left of the target,
         // rather than above it.
         goto MoveSrcDownFirst;
      }
      goto MoveSrcRightFirst;
   }
   if (destCol - sourceCol < destRow - sourceRow) {
MoveSrcDownFirst:
      // the source is within the 90š-135š octant.
      // we want to move the blank square just below the source.
      // we will end up just to the left of the target.
      if (gBlankCol == sourceCol && gBlankRow < sourceRow) {
         // the blank is on top of the source.  moving it
         // down would move our square in the wrong direction.
         BlankRight();
      }
      // in case the source is just to the upper left of the target,
      // we have to make sure we don’t accidentally munge the protected area.
      if (gBlankCol > destCol) MoveBlankToCol(destCol);
      MoveBlankToRow(sourceRow + 1);
      MoveBlankToCol(sourceCol);
      BlankUp();    sourceRow++;
      BlankRight(); BlankDown();
      // the blank is now to the right of the source.
   } else {
MoveSrcRightFirst:
      // the source is within the 135š-180š octant.
      // we want to move the blank square just to the right of the source.
      // we will end up just above the target.
      if (gBlankRow == sourceRow && gBlankCol < sourceCol) {
         // the blank is to the left of the source.  moving it
         // to the right would move our square in the wrong direction.
         BlankDown();
      }
      // in case the source is just to the upper left of the target,
      // we have to make sure we don't accidentally munge the protected area.
      if (gBlankRow > destRow) MoveBlankToRow(destRow);
      MoveBlankToCol(sourceCol + 1);
      MoveBlankToRow(sourceRow);
      // the blank is now to the right of the source.
   }
   BlankLeft();
   sourceCol++;
   // the blank is now to the left of the source.
   // are we done yet?
   for (;;) {
      if (sourceCol == destCol) {
         if (sourceRow == destRow) return;
         // the blank is still to the left of the source.
         BlankDown();  BlankRight(); BlankUp();   sourceRow++;
         goto WereInTheSameColumnNow;
      }
      if (sourceRow == destRow) {
         goto WereOnTheSameRowNow;
      }
      BlankDown();  BlankRight(); BlankUp();    sourceRow++;
      BlankRight(); BlankDown();  BlankLeft();  sourceCol++;
   }
}

QuickBlock
static void *QuickBlock(long size) {
   Handle   h = NewHandle(size);
   if (h == 0) return 0;
   HLock(h);
   return *h;
}

DisposeBlock
static void DisposeBlock(void *block) {
   Handle   h = RecoverHandle(block);
   DisposeHandle(h);
}


SolveTiles
void SolveTiles(
  long *tiles,      /* pointer to array of tiles where */
  long numRows,     /*   tile (row,col) is at */
  long numCols,     /*   *(tiles + row*numCols + col) */
  MoveProc MakeMove /* Callback procedure to move a tile */
) {
   long   col, row, target, tile, correctTile;
   long   colsToGo, rowsToGo;
   long   *tileRover, *pieceRow, *pieceCol;

   pieceRow = QuickBlock(numRows * numCols * sizeof(long));
   if (pieceRow == 0) return;
   pieceCol = QuickBlock(numRows * numCols * sizeof(long));
   if (pieceCol == 0) {
      DisposeBlock(pieceRow);
      return;
   }
   gPieceRow = pieceRow;
   gPieceCol = pieceCol;
   gMakeMove = MakeMove;
   gTiles = tiles;
   gNumCols = numCols;

   tileRover = tiles;
   correctTile = 0;
   for (row = 0; row < numRows; row++) {
      for (col = 0; col < numCols; col++) {
         tile = *tileRover++;
         pieceRow[tile] = row;
         pieceCol[tile] = col;
         correctTile++;
      }
   }

   gBlankSquare = &tiles[gBlankRow * numCols + gBlankCol];

   rowsToGo = numRows;
   colsToGo = numCols;

   for (;;) {
      if (rowsToGo >= colsToGo) {
         if (rowsToGo <= 2) break;
         row = rowsToGo - 1;
         for (col = colsToGo - 1; col > 1; col--) {
            tile = row * numCols + col;
            MoveAPiece(tile, row, col, tile - 1);
         }
         tile = row * numCols;
         if (pieceRow[tile]     != row || 
             pieceCol[tile    ] != 0   ||
             pieceRow[tile + 1] != row || 
             pieceCol[tile + 1] != 1) {
            MoveAPiece(tile, row, 1, tile + 1);
            if (gBlankRow == row) {
               if (tiles[(row - 1) * numCols] == tile + 1) {
                  // problem scenario 1
rowScenario1:
                  BlankRight(); BlankUp();    BlankLeft();
                  BlankUp();    BlankRight(); BlankDown();
                  BlankDown();  BlankLeft();  BlankUp();
                  BlankRight(); BlankUp();    BlankLeft();
                  BlankDown();  BlankDown();  BlankRight();
                  BlankUp();
                  goto nextRow;
               }
            } else if (tiles[row * numCols] == tile + 1) {
               // problem scenario 2
               MoveBlankToCol(0);
               MoveBlankToRow(row);
               goto rowScenario1;
            }
            MoveAPiece(tile + 1, row, 1, 0);
         }
nextRow:   if (gBlankRow == row) BlankUp();
         if (pieceRow[tile]     != row || 
             pieceCol[tile    ] != 0) {
            // the “12” isn’t in place...
            Debugger();
         }
      rowsToGo--;
      } else {
         if (colsToGo <= 2) break;
         col = colsToGo - 1;
         for (row = rowsToGo - 1; row > 1; row--) {
            tile = row * numCols + col;
            MoveAPiece(tile, row, col, tile - numCols);
         }
         if (pieceRow[          col] != 0 || 
             pieceCol[          col] != col ||
             pieceRow[numCols + col] != 1 || 
             pieceCol[numCols + col] != col) {
            MoveAPiece(col, 1, col, col + numCols);
            if (gBlankCol == col) {
               if (tiles[col - 1] == numCols + col) {
                  // problem scenario 1
colScenario1:
                  BlankDown();  BlankLeft();  BlankUp();
                  BlankLeft();  BlankDown();  BlankRight();
                  BlankRight(); BlankUp();    BlankLeft();
                  BlankDown();  BlankLeft();  BlankUp();
                  BlankRight(); BlankRight(); BlankDown();
                  BlankLeft();
                  goto nextCol;
               }
            } else if (tiles[col] == numCols + col) {
               // problem scenario 2
               MoveBlankToRow(0);
               MoveBlankToCol(col);
               goto colScenario1;
            }
            MoveAPiece(numCols + col, 1, col, 0);
         }
nextCol:   if (gBlankCol == col) BlankLeft();
         if (pieceRow[          col] != 0 || 
             pieceCol[          col] != col) {
            // the “3” isn’t in place...
            Debugger();
         }
         colsToGo--;
      }
   }

   if (gBlankRow == 0) {
      if (gBlankCol == 0) {
         if (pieceRow[1] == 0) goto pos0123;
         if (pieceCol[1] == 0) goto pos0312;
                               goto pos0231;
      } else {
         if (pieceRow[1] == 0) goto pos1023;
         if (pieceCol[1] == 0) goto pos3012;
                               goto pos2031;
      }
   } else {
      if (gBlankCol == 0) {
         if (pieceRow[1] != 0) goto pos3201;
         if (pieceCol[1] == 0) goto pos1302;
                               goto pos2103;
      } else {
         if (pieceRow[1] != 0) goto pos3210;
         if (pieceCol[1] == 0) goto pos1320;
                               goto pos2130;
      }
   }

pos3012: BlankLeft();
pos0312: BlankDown();
pos1302: BlankRight();
pos1320: BlankUp();
pos1023: BlankLeft();
         goto all_done;

pos3210: BlankLeft();
pos3201: BlankUp();
pos0231: BlankRight();
pos2031: BlankDown();
pos2130: BlankLeft();
pos2103: BlankUp();
pos0123: goto all_done;

all_done:
   DisposeBlock(pieceRow); gPieceRow = 0;
   DisposeBlock(pieceCol); gPieceCol = 0;
}

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Fresh From the Land Down Under – The Tou...
After a two week hiatus, we are back with another episode of The TouchArcade Show. Eli is fresh off his trip to Australia, which according to him is very similar to America but more upside down. Also kangaroos all over. Other topics this week... | Read more »
TouchArcade Game of the Week: ‘Dungeon T...
I’m a little conflicted on this week’s pick. Pretty much everyone knows the legend of Dungeon Raid, the match-3 RPG hybrid that took the world by storm way back in 2011. Everyone at the time was obsessed with it, but for whatever reason the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for July 19th, 2024. In today’s article, we finish up the week with the unusual appearance of a review. I’ve spent my time with Hot Lap Racing, and I’m ready to give my verdict. After... | Read more »
Draknek Interview: Alan Hazelden on Thin...
Ever since I played my first release from Draknek & Friends years ago, I knew I wanted to sit down with Alan Hazelden and chat about the team, puzzle games, and much more. | Read more »
The Latest ‘Marvel Snap’ OTA Update Buff...
I don’t know about all of you, my fellow Marvel Snap (Free) players, but these days when I see a balance update I find myself clenching my… teeth and bracing for the impact to my decks. They’ve been pretty spicy of late, after all. How will the... | Read more »
‘Honkai Star Rail’ Version 2.4 “Finest D...
HoYoverse just announced the Honkai Star Rail (Free) version 2.4 “Finest Duel Under the Pristine Blue" update alongside a surprising collaboration. Honkai Star Rail 2.4 follows the 2.3 “Farewell, Penacony" update. Read about that here. | Read more »
‘Vampire Survivors+’ on Apple Arcade Wil...
Earlier this month, Apple revealed that poncle’s excellent Vampire Survivors+ () would be heading to Apple Arcade as a new App Store Great. I reached out to poncle to check in on the DLC for Vampire Survivors+ because only the first two DLCs were... | Read more »
Homerun Clash 2: Legends Derby opens for...
Since launching in 2018, Homerun Clash has performed admirably for HAEGIN, racking up 12 million players all eager to prove they could be the next baseball champions. Well, the title will soon be up for grabs again, as Homerun Clash 2: Legends... | Read more »
‘Neverness to Everness’ Is a Free To Pla...
Perfect World Games and Hotta Studio (Tower of Fantasy) announced a new free to play open world RPG in the form of Neverness to Everness a few days ago (via Gematsu). Neverness to Everness has an urban setting, and the two reveal trailers for it... | Read more »
Meditative Puzzler ‘Ouros’ Coming to iOS...
Ouros is a mediative puzzle game from developer Michael Kamm that launched on PC just a couple of months back, and today it has been revealed that the title is now heading to iOS and Android devices next month. Which is good news I say because this... | Read more »

Price Scanner via MacPrices.net

Amazon is still selling 16-inch MacBook Pros...
Prime Day in July is over, but Amazon is still selling 16-inch Apple MacBook Pros for $500-$600 off MSRP. Shipping is free. These are the lowest prices available this weekend for new 16″ Apple... Read more
Walmart continues to sell clearance 13-inch M...
Walmart continues to offer clearance, but new, Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBooks... Read more
Apple is offering steep discounts, up to $600...
Apple has standard-configuration 16″ M3 Max MacBook Pros available, Certified Refurbished, starting at $2969 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free,... Read more
Save up to $480 with these 14-inch M3 Pro/M3...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
Amazon has clearance 9th-generation WiFi iPad...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Apple is offering a $50 discount on 2nd-gener...
Apple has Certified Refurbished White and Midnight HomePods available for $249, Certified Refurbished. That’s $50 off MSRP and the lowest price currently available for a full-size Apple HomePod today... Read more
The latest MacBook Pro sale at Amazon: 16-inc...
Amazon is offering instant discounts on 16″ M3 Pro and 16″ M3 Max MacBook Pros ranging up to $400 off MSRP as part of their early July 4th sale. Shipping is free. These are the lowest prices... Read more
14-inch M3 Pro MacBook Pros with 36GB of RAM...
B&H Photo has 14″ M3 Pro MacBook Pros with 36GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 Pro MacBook Pro (... Read more
14-inch M3 MacBook Pros with 16GB of RAM on s...
B&H Photo has 14″ M3 MacBook Pros with 16GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $150-$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 MacBook Pro (... Read more
Amazon is offering $170-$200 discounts on new...
Amazon is offering a $170-$200 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at $1129 for models with 8GB of RAM and 256GB of storage: – 15″ M3... Read more

Jobs Board

*Apple* Systems Engineer - Chenega Corporati...
…LLC,** a **Chenega Professional Services** ' company, is looking for a ** Apple Systems Engineer** to support the Information Technology Operations and Maintenance Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
*Apple* / Mac Administrator - JAMF Pro - Ame...
Amentum is seeking an ** Apple / Mac Administrator - JAMF Pro** to provide support with the Apple Ecosystem to include hardware and software to join our team and Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.