Hi
David &
Blue,
Thanks for your kind consideration and detailed responses.
David P Bird wrote:It appears that this routine could miss a tuple when there are 9 unresolved cells but I couldn't compose a case to prove that, and in practice I have never been aware of one. (I bet Blue could find one though.)
Blue wrote:(Small) naked sets with large hidden complements, can be missed.
I am working for Bitwise searching through each combination of Cells in Unit (or House) for Naked/Hidden tuples as follows:
- Code: Select all
for(y = 0; y < 27; ++y) // Search Naked/Hidden Tuples Candidates within each Unit
{
int k[10] = {g[l[y][0]], g[l[y][1]], g[l[y][2]], g[l[y][3]],
g[l[y][4]], g[l[y][5]], g[l[y][6]], g[l[y][7]], g[l[y][8]], 0};
for(a = 0; a < 36; ++a) // Search 36 pairs per Unit
{
if(!k[T[a][0]] || !k[T[a][1]])
continue; // Check empty Cell Candidate
k[9] = k[T[a][0]] | k[T[a][1]];
if(B[k[9]] == 2 && k[9] & (k[T[a][2]] | k[T[a][3]] |
k[T[a][4]] | k[T[a][5]] | k[T[a][6]] | k[T[a][7]] | k[T[a][8]]))
{ // Found Naked pair Candidates
g[l[y][T[a][2]]] &= ~k[9];
g[l[y][T[a][3]]] &= ~k[9];
g[l[y][T[a][4]]] &= ~k[9];
g[l[y][T[a][5]]] &= ~k[9];
g[l[y][T[a][6]]] &= ~k[9];
g[l[y][T[a][7]]] &= ~k[9];
g[l[y][T[a][8]]] &= ~k[9];
if(solve(p))
return 1;
g[l[y][T[a][2]]] = k[T[a][2]];
g[l[y][T[a][3]]] = k[T[a][3]];
g[l[y][T[a][4]]] = k[T[a][4]];
g[l[y][T[a][5]]] = k[T[a][5]];
g[l[y][T[a][6]]] = k[T[a][6]];
g[l[y][T[a][7]]] = k[T[a][7]];
g[l[y][T[a][8]]] = k[T[a][8]];
}
k[9] = ~(k[T[a][2]] | k[T[a][3]] | k[T[a][4]] | k[T[a][5]] |
k[T[a][6]] | k[T[a][7]] | k[T[a][8]] | W[s[l[y][T[a][2]]]] |
W[s[l[y][T[a][3]]]] | W[s[l[y][T[a][4]]]] | W[s[l[y][T[a][5]]]] |
W[s[l[y][T[a][6]]]] | W[s[l[y][T[a][7]]]] | W[s[l[y][T[a][8]]]]) & 511;
if(B[k[9]] == 2 && B[k[T[a][0]] | k[T[a][1]]] > 2)
{ // Found Hidden pair Candidates
g[l[y][T[a][0]]] &= k[9];
g[l[y][T[a][1]]] &= k[9];
if(solve(p))
return 1;
g[l[y][T[a][0]]] = k[T[a][0]];
g[l[y][T[a][1]]] = k[T[a][1]];
}
}
for(; a < 120; ++a) // Search 84 triples per Unit
{
if(!k[T[a][0]] || !k[T[a][1]] || !k[T[a][2]])
continue; // Check empty Cell Candidate
k[9] = k[T[a][0]] | k[T[a][1]] | k[T[a][2]];
if(B[k[9]] == 3 && k[9] & (k[T[a][3]] | k[T[a][4]] |
k[T[a][5]] | k[T[a][6]] | k[T[a][7]] | k[T[a][8]]))
{ // Found Naked triple Candidates
g[l[y][T[a][3]]] &= ~k[9];
g[l[y][T[a][4]]] &= ~k[9];
g[l[y][T[a][5]]] &= ~k[9];
g[l[y][T[a][6]]] &= ~k[9];
g[l[y][T[a][7]]] &= ~k[9];
g[l[y][T[a][8]]] &= ~k[9];
if(solve(p))
return 1;
g[l[y][T[a][3]]] = k[T[a][3]];
g[l[y][T[a][4]]] = k[T[a][4]];
g[l[y][T[a][5]]] = k[T[a][5]];
g[l[y][T[a][6]]] = k[T[a][6]];
g[l[y][T[a][7]]] = k[T[a][7]];
g[l[y][T[a][8]]] = k[T[a][8]];
}
k[9] = ~(k[T[a][3]] | k[T[a][4]] | k[T[a][5]] | k[T[a][6]] | k[T[a][7]] |
k[T[a][8]] | W[s[l[y][T[a][3]]]] | W[s[l[y][T[a][4]]]] |
W[s[l[y][T[a][5]]]] | W[s[l[y][T[a][6]]]] | W[s[l[y][T[a][7]]]] |
W[s[l[y][T[a][8]]]]) & 511;
if(B[k[9]] == 3 && B[k[T[a][0]] | k[T[a][1]] | k[T[a][2]]] > 3)
{ // Found Hidden triple Candidates
g[l[y][T[a][0]]] &= k[9];
g[l[y][T[a][1]]] &= k[9];
g[l[y][T[a][2]]] &= k[9];
if(solve(p))
return 1;
g[l[y][T[a][0]]] = k[T[a][0]];
g[l[y][T[a][1]]] = k[T[a][1]];
g[l[y][T[a][2]]] = k[T[a][2]];
}
}
for(; a < 246; ++a) // Search 126 quads per Unit
{
if(!k[T[a][0]] || !k[T[a][1]] || !k[T[a][2]] || !k[T[a][3]])
continue; // Check empty Cell Candidate
k[9] = k[T[a][0]] | k[T[a][1]] | k[T[a][2]] | k[T[a][3]];
if(B[k[9]] == 4 && k[9] & (k[T[a][4]] | k[T[a][5]] |
k[T[a][6]] | k[T[a][7]] | k[T[a][8]]))
{ // Found Naked quad Candidates
g[l[y][T[a][4]]] &= ~k[9];
g[l[y][T[a][5]]] &= ~k[9];
g[l[y][T[a][6]]] &= ~k[9];
g[l[y][T[a][7]]] &= ~k[9];
g[l[y][T[a][8]]] &= ~k[9];
if(solve(p))
return 1;
g[l[y][T[a][4]]] = k[T[a][4]];
g[l[y][T[a][5]]] = k[T[a][5]];
g[l[y][T[a][6]]] = k[T[a][6]];
g[l[y][T[a][7]]] = k[T[a][7]];
g[l[y][T[a][8]]] = k[T[a][8]];
}
k[9] = ~(k[T[a][4]] | k[T[a][5]] | k[T[a][6]] | k[T[a][7]] | k[T[a][8]] |
W[s[l[y][T[a][4]]]] | W[s[l[y][T[a][5]]]] | W[s[l[y][T[a][6]]]] |
W[s[l[y][T[a][7]]]] | W[s[l[y][T[a][8]]]]) & 511;
if(B[k[9]] == 4 && B[k[T[a][0]] | k[T[a][1]] | k[T[a][2]] | k[T[a][3]]] > 4)
{ // Found Hidden quad Candidates
g[l[y][T[a][0]]] &= k[9];
g[l[y][T[a][1]]] &= k[9];
g[l[y][T[a][2]]] &= k[9];
g[l[y][T[a][3]]] &= k[9];
if(solve(p))
return 1;
g[l[y][T[a][0]]] = k[T[a][0]];
g[l[y][T[a][1]]] = k[T[a][1]];
g[l[y][T[a][2]]] = k[T[a][2]];
g[l[y][T[a][3]]] = k[T[a][3]];
}
}
}
Where:
y integer iterates 27 times for each Unit
k array is used to keep 9 Cells original Candidates for rollback purpose
g array holds 81 Cells 9 Candidates (givens)
l array holds 9 Cell positions per Unit
a integer iterates 36 times for each pair combination per Unit
T array holds 246 enumerated combinations of 9 Cells per Unit (tuples), i.e., first 36 for pair, next 84 for triple and last 126 for quad
B array holds 512 enumerated combinations of 9 bit count
W array holds 10 enumerated single bit per digit, i.e., { 0, 1, 2, 4, 8, 16, 32, 64, 128, 256}.
p integer iterates empty cell position.
please note that the code is not finalized yet as I am still under testing phase of my routine. However, thanks for providing such an appropriate example puzzles for rigorous testing purpose.
Updated 20151007:
I made some fine tuning in Hidden tuples, i.e., included filled cells checking.
I have checked and found both Naked and Hidden Tuples are now working fine.
I have taken only one puzzle from
this for Hidden Quad checking purpose:
- Code: Select all
901500046425090081860010020502000000019000460600000002196040253200060817000001694
Regards,
R. Jamil