While I am studying X-Wing, Swordfish and Jellyfish elimination methods in order to implement in to my Bitwise Sudoku Solver program, got an idea. Here is proposed pseudo code for expert review and comments/suggestions please:
- Code: Select all
for (int A = 0; A < 9; ++A)// Check X-Wing for each candidate
for (int Y = 0; Y < 8; ++Y)
{ // Check X-Wing for first Row Unit
int K = (g[l[Y][0]] >> A) & 1 | ((g[l[Y][1]] >> A) & 1) << 1 |
((g[l[Y][2]] >> A) & 1) << 2 | ((g[l[Y][3]] >> A) & 1) << 3 |
((g[l[Y][4]] >> A) & 1) << 4 | ((g[l[Y][5]] >> A) & 1) << 5 |
((g[l[Y][6]] >> A) & 1) << 6 | ((g[l[Y][7]] >> A) & 1) << 7 |
((g[l[Y][8]] >> A) & 1) << 8
if (B[K] != 2)
continue; // Skip first Row Unit for candidate found more than 2 unsolved Cell positions
for (y = Y + 1; Y < 9; ++Y)
{ // Check X-Wing for second Row Unit
if (K != (g[l[y][0]] >> A) & 1 | ((g[l[y][1]] >> A) & 1) << 1 |
((g[l[y][2]] >> A) & 1) << 2 | ((g[l[y][3]] >> A) & 1) << 3 |
((g[l[y][4]] >> A) & 1) << 4 | ((g[l[y][5]] >> A) & 1) << 5 |
((g[l[y][6]] >> A) & 1) << 6 | ((g[l[y][7]] >> A) & 1) << 7 |
((g[l[y][8]] >> A) & 1) << 8)
continue; // Skip second Row Unit if not equals to first Row Unit
for (int X = K; a = b[X & -X] + 9; X &= X - 1)
// Check each Column Unit
if (B[(g[l[X][0]] >> A) & 1 | ((g[l[X][1]] >> A) & 1) << 1 |
((g[l[X][2]] >> A) & 1) << 2 | ((g[l[X][3]] >> A) & 1) << 3 |
((g[l[X][4]] >> A) & 1) << 4 | ((g[l[X][5]] >> A) & 1) << 5 |
((g[l[X][6]] >> A) & 1) << 6 | ((g[l[X][7]] >> A) & 1) << 7 |
((g[l[X][8]] >> A) & 1) << 8] > 2)
{ // Found X-Wing
// do backup, eliminations then recursive call solve function then restore
}
}
}
Similarly, for swordfish and Jellyfish, loop third row unit and forth row unit respectively and check union of first, second, third [and forth] row unit for candidate found between 2 and 3/4 unsolved cell positions.
Also, for column, repeat same steps in column loops and then row checking.
Note: there might be some error due unintentional typo mistakes as not yet checked, but hope that overall logic works.
R. Jamil