Код | #include <stdio.h>
#define W 1 #define B 2 #define H 0 #define SIZE 11
char aPool[SIZE] = {W,W,W,W,W,H,B,B,B,B,B};
char holePos = 5; // initial position of the hole
bool isFilan() { return aPool[0] == B && aPool[1] == B && aPool[2] == B && aPool[3] == B && aPool[4] == B && aPool[5] == H && aPool[6] == W && aPool[7] == W && aPool[8] == W && aPool[9] == W && aPool[10] == W; }
void processStep() { static int iStep = 0;
iStep ++;
bool bChanged = false; // Nearesrt White ball if (holePos > 0 && aPool[holePos - 1] == W) { bChanged = true;
aPool[holePos] = W; holePos --; aPool[holePos] = H;
processStep();// next Movement
// lets undo
aPool[holePos] = W; holePos ++; aPool[holePos] = H; } // Nexxt Whilt Ball if (holePos > 1 && aPool[holePos - 2] == W) { bChanged = true;
aPool[holePos] = W; holePos -= 2; aPool[holePos] = H;
processStep();// next Movement
// lets undo
aPool[holePos] = W; holePos += 2; aPool[holePos] = H; } // Nearest Black ball if ((holePos < SIZE - 1) && aPool[holePos + 1] == B) { bChanged = true;
aPool[holePos] = B; holePos ++; aPool[holePos] = H;
processStep();// next Movement
// lets undo
aPool[holePos] = B; holePos --; aPool[holePos] = H; } // Next Black ball if ((holePos < SIZE - 2) && aPool[holePos + 2] == B) { bChanged = true;
aPool[holePos] = B; holePos += 2; aPool[holePos] = H;
processStep();// next Movement
// lets undo
aPool[holePos] = B; holePos -= 2; aPool[holePos] = H; }
if (!bChanged)// Final configuration { for (int i = 0; i < SIZE; i++) { printf("%d ", aPool[i]); }
if (isFilan()) { printf("FINAL %d steps", iStep); }
printf("\n"); }
iStep --;
}
void main() { processStep(); }
|
получается два симметричных по ходам решенияв 36 ходов. |