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

Dropbox 193.4.5594 - Cloud backup and sy...
Dropbox is a file hosting service that provides cloud storage, file synchronization, personal cloud, and client software. It is a modern workspace that allows you to get to all of your files, manage... Read more
Google Chrome 122.0.6261.57 - Modern and...
Google Chrome is a Web browser by Google, created to be a modern platform for Web pages and applications. It utilizes very fast loading of Web pages and has a V8 engine, which is a custom built... Read more
Skype 8.113.0.210 - Voice-over-internet...
Skype is a telecommunications app that provides HD video calls, instant messaging, calling to any phone number or landline, and Skype for Business for productive cooperation on the projects. This... Read more
Tor Browser 13.0.10 - Anonymize Web brow...
Using Tor Browser you can protect yourself against tracking, surveillance, and censorship. Tor was originally designed, implemented, and deployed as a third-generation onion-routing project of the U.... Read more
Deeper 3.0.4 - Enable hidden features in...
Deeper is a personalization utility for macOS which allows you to enable and disable the hidden functions of the Finder, Dock, QuickTime, Safari, iTunes, login window, Spotlight, and many of Apple's... Read more
OnyX 4.5.5 - Maintenance and optimizatio...
OnyX is a multifunction utility that you can use to verify the startup disk and the structure of its system files, to run miscellaneous maintenance and cleaning tasks, to configure parameters in the... Read more
Hopper Disassembler 5.14.1 - Binary disa...
Hopper Disassembler is a binary disassembler, decompiler, and debugger for 32- and 64-bit executables. It will let you disassemble any binary you want, and provide you all the information about its... Read more

Latest Forum Discussions

See All

Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »
Live, Playdate, Live! – The TouchArcade...
In this week’s episode of The TouchArcade Show we kick things off by talking about all the games I splurged on during the recent Playdate Catalog one-year anniversary sale, including the new Lucas Pope jam Mars After Midnight. We haven’t played any... | Read more »
TouchArcade Game of the Week: ‘Vroomies’
So here’s a thing: Vroomies from developer Alex Taber aka Unordered Games is the Game of the Week! Except… Vroomies came out an entire month ago. It wasn’t on my radar until this week, which is why I included it in our weekly new games round-up, but... | Read more »
SwitchArcade Round-Up: ‘MLB The Show 24’...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for March 15th, 2024. We’re closing out the week with a bunch of new games, with Sony’s baseball franchise MLB The Show up to bat yet again. There are several other interesting games to... | Read more »
Steam Deck Weekly: WWE 2K24 and Summerho...
Welcome to this week’s edition of the Steam Deck Weekly. The busy season has begun with games we’ve been looking forward to playing including Dragon’s Dogma 2, Horizon Forbidden West Complete Edition, and also console exclusives like Rise of the... | Read more »
Steam Spring Sale 2024 – The 10 Best Ste...
The Steam Spring Sale 2024 began last night, and while it isn’t as big of a deal as say the Steam Winter Sale, you may as well take advantage of it to save money on some games you were planning to buy. I obviously recommend checking out your own... | Read more »
New ‘SaGa Emerald Beyond’ Gameplay Showc...
Last month, Square Enix posted a Let’s Play video featuring SaGa Localization Director Neil Broadley who showcased the worlds, companions, and more from the upcoming and highly-anticipated RPG SaGa Emerald Beyond. | Read more »
Choose Your Side in the Latest ‘Marvel S...
Last month, Marvel Snap (Free) held its very first “imbalance" event in honor of Valentine’s Day. For a limited time, certain well-known couples were given special boosts when conditions were right. It must have gone over well, because we’ve got a... | Read more »
Warframe welcomes the arrival of a new s...
As a Warframe player one of the best things about it launching on iOS, despite it being arguably the best way to play the game if you have a controller, is that I can now be paid to talk about it. To whit, we are gearing up to receive the first... | Read more »
Apple Arcade Weekly Round-Up: Updates an...
Following the new releases earlier in the month and April 2024’s games being revealed by Apple, this week has seen some notable game updates and events go live for Apple Arcade. What The Golf? has an April Fool’s Day celebration event going live “... | Read more »

Price Scanner via MacPrices.net

Apple Education is offering $100 discounts on...
If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take $100 off the price of a new M3 MacBook Air.... Read more
Apple Watch Ultra 2 with Blood Oxygen feature...
Best Buy is offering Apple Watch Ultra 2 models for $50 off MSRP on their online store this week. Sale prices available for online orders only, in-store prices may vary. Order online, and choose... Read more
New promo at Sams Club: Apple HomePods for $2...
Sams Club has Apple HomePods on sale for $259 through March 31, 2024. Their price is $40 off Apple’s MSRP, and both Space Gray and White colors are available. Sale price is for online orders only, in... Read more
Get Apple’s 2nd generation Apple Pencil for $...
Apple’s Pencil (2nd generation) works with the 12″ iPad Pro (3rd, 4th, 5th, and 6th generation), 11″ iPad Pro (1st, 2nd, 3rd, and 4th generation), iPad Air (4th and 5th generation), and iPad mini (... Read more
10th generation Apple iPads on sale for $100...
Best Buy has Apple’s 10th-generation WiFi iPads back on sale for $100 off MSRP on their online store, starting at only $349. With the discount, Best Buy’s prices are the lowest currently available... Read more
iPad Airs on sale again starting at $449 on B...
Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices again for $150 off Apple’s MSRP, starting at $449. Sale prices for online orders only, in-store price may vary. Order online, and choose... Read more
Best Buy is blowing out clearance 13-inch M1...
Best Buy is blowing out clearance Apple 13″ M1 MacBook Airs this weekend for only $649.99, or $350 off Apple’s original MSRP. Sale prices for online orders only, in-store prices may vary. Order... Read more
Low price alert! You can now get a 13-inch M1...
Walmart has, for the first time, begun offering new Apple MacBooks for sale on their online store, albeit clearance previous-generation models. They now have the 13″ M1 MacBook Air (8GB RAM, 256GB... Read more
Best Apple MacBook deal this weekend: Get the...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New 15-inch M3 MacBook Air (Midnight) on sale...
Amazon has the new 15″ M3 MacBook Air (8GB RAM/256GB SSD/Midnight) in stock and on sale today for $1249.99 including free shipping. Their price is $50 off MSRP, and it’s the lowest price currently... Read more

Jobs Board

Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
Senior Software Engineer - *Apple* Fundamen...
…center of Microsoft's efforts to empower our users to do more. The Apple Fundamentals team focused on defining and improving the end-to-end developer experience in Read more
Relationship Banker *Apple* Valley Main - W...
…Alcohol Policy to learn more. **Company:** WELLS FARGO BANK **Req Number:** R-350696 **Updated:** Mon Mar 11 00:00:00 UTC 2024 **Location:** APPLE VALLEY,California Read more
Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill WellSpan Medical Group, York, PA | Nursing | Nursing Support | FTE: 1 | Regular | Tracking Code: 200555 Apply Now Read more
Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.