Ruud,
I used to return the shortest chain but now I evaluate for each chain found, regardless of length, the following four figures:
- The number of candidate values remaining for the cell where the chain elimination occurred.
- The number of candidate positions remaining for the eliminated value in the row, column and box of the cell where the elimination occurred.
Any chain that leaves just a single candidate is returned immediately. Otherwise, the chain that leaves the smallest number of candidates is returned. Since there are likely to be many such chains, I return the chain for which the greatest number of eliminations has occurred (usually just one elimination occurs but some chains, e.g. X-Wing chains, eliminate more). Finally, when I still have many chains, I return the first such chain found, as it will be the shortest.
My solver runs the 'Many-Values Chains' routine twice - first without tables then with them, which means that sometimes a non-table chain is returned that doesn't leave a single candidate in a situation where a table chain would have left just a single candidate. This is because I don't really like table chains and I would rather see a slightly longer solution that avoids them.
With these rules in place (clearly they are in no sense optimal), the solver returns the following results:
Locked Sector Candidates 19 eliminated
Disjoint Subsets (pairs etc.) 11
Single-Valued Chains (fishy cycles) 6
Two-Sector Disjoint Subsets 2
Conditional Disjoint Subsets 2
Many-Valued Chains 28
Analysed in 23.8s
With guesses but no chains (to compare with
QBasicMac):
Locked Sector Candidates 37
Disjoint Subsets 13
# Guesses 7 (Not the number eliminated, clearly)
Analysed in 0.016s.
I'm yet to implement one piece of table logic. Of course, I'd hope to see the results improve with it in place. Here's my log for the nightmare third move. I'd be interested to see how my chains compare with yours. Links such as r4c2+{?F1|1??}+r8c3 are
Inferred links generated from tables. I will add extra debug later to identify the chains from which these links have been inferred.
- Code: Select all
3. Consider the chains r4c4-8-r4c2+{?F1|1??}+r8c3-4-r6c5+{?F1|7??}+r8c5 and r4c4-8-r4c2-8-r4c4+{?F4|7??}+r8c5~5~r7c4.
Regardless of whether the cell r4c4 contains the value 8 or not, the cell r8c5 cannot contain the value 7.
- The move r8c5:=7 has been eliminated.
Consider the chains r8c5+{??4|1?F}+r8c6+{??5|1F?}+r5c1-4-r6c5 and r8c5-3-r8c6.
Since it is certain that the cell r8c6 will not contain at least one of the values 1 and 3, the cell r8c5 cannot contain the value 4.
- The move r8c5:=4 has been eliminated.
Consider the chains r1c2+{??8|5?F}+r4c8 and r1c2+{??8|5?F}+r7c8.
Since it is certain that Column 8 will not contain the value 5 in at least one of the cells r4c8 and r7c8, the cell r1c2 does not contain the value 8.
- The move r1c2:=8 has been eliminated.
Consider the chains r1c3+{??9|8?F}+r5c4 and r1c3+{??9|8?F}+r2c4~3~r2c8.
Since it is certain that Column 4 will not contain the value 8 in at least one of the cells r5c4 and r2c4, the cell r1c3 does not contain the value 9.
- The move r1c3:=9 has been eliminated.
The value 9 in Box 7 must lie in Column 3.
- The move r9c1:=9 has been eliminated.
Consider the chains r5c6+{??3|2?F}+r9c6 and r5c6+{??3|2?F}+r9c8.
Since it is certain that Row 9 will not contain the value 2 in at least one of the cells r9c6 and r9c8, the cell r5c6 does not contain the value 3.
- The move r5c6:=3 has been eliminated.
Consider the chains r7c3+{??7|5?F}+r7c9+{??1|5?F}+r9c4+{??9|9?F}+r1c1 and r7c3-9-r7c9.
Since it is certain that the cell r7c9 will not contain at least one of the values 5 and 9, the cell r7c3 cannot contain the value 7.
- The move r7c3:=7 has been eliminated.
Consider the chains r1c7+{?F7|1??}+r8c3 and r2c8+{?F7|1??}+r8c3.
Since it is certain that Box 3 will not contain the value 7 in at least one of the cells r1c7 and r2c8, the cell r8c3 does not contain the value 1.
- The move r8c3:=1 has been eliminated.
The value 1 in Box 8 must lie in Row 8.
- The move r9c6:=1 has been eliminated.
The values 1 and 3 occupy the cells r8c5 and r8c6 in some order.
- The moves r8c5:=2 and r8c6:=2 have been eliminated.
The value 2 in Box 9 must lie in Row 8.
- The moves r9c7:=2 and r9c8:=2 have been eliminated.
The value 2 in Box 6 must lie in Column 8.
- The moves r4c7:=2, r4c9:=2, r5c7:=2, r5c9:=2 and r6c9:=2 have been eliminated.
Consider the chain r6c8~5~r6c3~7~r5c1-7-r9c1~7~r9c8~5~r6c8.
When the cell r6c8 contains the value 5, the chain is self-contradicting.
Therefore, the cell r6c8 cannot contain the value 5.
- The move r6c8:=5 has been eliminated.
Consider the chains r6c6+{??5|4?F}+r9c4 and r6c6+{??5|4?F}+r9c7-2-r5c1-7-r9c1.
Since it is certain that Row 9 will not contain the value 4 in at least one of the cells r9c4 and r9c7, the cell r6c6 does not contain the value 5.
- The move r6c6:=5 has been eliminated.
Consider the chain r6c8-<7|4>-r6c5~4~r7c5~7~r7c8.
When the cell r7c8 contains the value 7, so does the cell r6c8 - a contradiction.
Therefore, the cell r7c8 cannot contain the value 7.
- The move r7c8:=7 has been eliminated.
Consider the chain r1c5=1=r8c6-<4|7>-r7c5+{??1|2?T}+r1c5.
The cell r1c5 must contain the value 1 if it doesn't contain the value 2.
Therefore, these two values are the only candidates for the cell r1c5.
- The moves r1c5:=3, r1c5:=7 and r1c5:=9 have been eliminated.
Consider the chains r7c9~4~r7c5+{??3|2?F}+r1c5-1-r8c5 and r3c6~3~r8c6-1-r8c5.
Regardless of whether the cell r8c5 contains the value 1 or not, the cell r3c6 cannot contain the value 3.
- The move r3c6:=3 has been eliminated.
Consider the chains r9c4~7~r7c5+{??3|2?F}+r1c5-1-r8c5 and r1c6~3~r8c6-1-r8c5.
Regardless of whether the cell r8c5 contains the value 1 or not, the cell r1c6 cannot contain the value 3.
- The move r1c6:=3 has been eliminated.
Consider the chains r4c5+{??2|5?F}+r9c8~7~r6c3~7~r2c4 and r4c5+{??2|5?F}+r4c8.
Since it is certain that Column 8 will not contain the value 5 in at least one of the cells r9c8 and r4c8, the cell r4c5 does not contain the value 2.
- The move r4c5:=2 has been eliminated.
Consider the chain r6c5-2-r1c5=1=r8c6-<1|2>-r6c6.
The cell r6c6 must contain the value 2 if the cell r6c5 doesn't.
Therefore, these two cells are the only candidates for the value 2 in Row 6.
- The move r6c8:=2 has been eliminated.
The value 2 in Box 5 must lie in Row 6.
- The moves r4c4:=2, r5c4:=2 and r5c6:=2 have been eliminated.
The values 1 and 2 occupy the cells r4c8 and r5c8 in some order.
- The moves r4c8:=5, r5c8:=3, r5c8:=5 and r5c8:=7 have been eliminated.
Consider the chain r3c7-3-r3c4~3~r5c4-3-r5c7.
The cell r5c7 must contain the value 3 if the cell r3c7 doesn't.
Therefore, these two cells are the only candidates for the value 3 in Column 7.
- The moves r1c7:=3 and r2c7:=3 have been eliminated.
Consider the chain r3c4-3-r3c7-3-r5c7-3-r5c4.
The cell r5c4 must contain the value 3 if the cell r3c4 doesn't.
Therefore, these two cells are the only candidates for the value 3 in Column 4.
- The moves r1c4:=3 and r2c4:=3 have been eliminated.
The cell r1c2 is the only candidate for the value 3 in Row 1.