Sudoku Programmers Forum Index

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in          Games  Calendar

Log in to check your private messagesLog in to check your private messages   

Uniqueness tests

 
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Programming sudoku
View previous topic :: View next topic  
Author Message
noeldillabough

Joined: 12 Oct 2005
Posts: 16
:

Items
PostPosted: Fri Oct 21, 2005 9:33 pm    Post subject: Uniqueness tests Reply with quote

I would like to add uniqueness tests to my solver; it already checks if a puzzle has more than one solution so I can safely use this technique's extra assumption of having one solution.

As far as I know there are 4 forms of this pattern, I understand the basic ones but I definately don't have an overall understanding especially to be able to write a generalized search for this technique.

As a human I can see using

12|1234
12|1234

to remove 34 from the remainder of the right hand box but I"m unsure if this is right.

Can someone list off the forms of this test and how to spot them? For example they need a naked pair in a box that share the same row and col and a matching row/col set containing this naked pair in a neighboring box.
Back to top
View user's profile Send private message
Lummox JR

Joined: 07 Sep 2005
Posts: 202
:

Items
PostPosted: Sat Oct 22, 2005 7:27 am    Post subject: Reply with quote

For all of the A forms you need to look for a naked pair in the same box which also share a common line (column/row). Call these cells a and b, and their candidates we'll call X and Y. You then need to look for cell c which shares a common line with cell a (but not b) and has at least XY as candidates. (For the B forms, the pair ab need only occupy the same line, but a and c must share a box as well as a line.) Cell d, which also has the XY candidates and at least one more, is the 4th corner of the rectangle.

Test 1: Cell c must have exactly the same candidates as a and b, no extras. XY may be eliminated from cell d.

Test 2 and 2b: Cells c and d each have exactly three candidates XYZ, Z being the same for both cells. In the common box (2a only) and line shared by c and d, eliminate Z from all other cells. This is a special case of test 3.

Test 3 and 3b: Cells c and d both have extra candidates, which may be different and/or shared between the two cells. Those extra candidates make up set S, which has size N. (E.g., if c=126 and d=129, S=69 and N=2.) In each house (box or line) shared by c and d, look for a partial naked subset in N-1 cells which only includes the members of S, or a partial hidden subset (not including c and d) for XY and any members of S. (If the partial hidden subset is just XY, you need just one other cell. For XYZ, 2 cells, WXYZ 3 cells, and so on.) For naked subsets, eliminate S's members from all other cells in that house (except c and d). For hidden subsets, remove all other candidates from those cells. Do not eliminate anything from c or d. (Note: Partial naked and partial hidden subsets are complementary. If there are 6 unfilled cells in a row including c and d, and you have a partial naked pair, you also have a partial hidden triple. c and d together act as one cell instead of two in each subset.)

Test 4 and 4b: In the box and/or line shared by c and d, X may only appear in c and d. Eliminate Y from c and d. (If this case doesn't occur, switch X and Y in the previous sentences and check again.)

Of course none of this covers higher-order uniqueness cases 3x3, 4x4, or 6x6, but those are rare and not worth the effort.
Back to top
View user's profile Send private message
noeldillabough

Joined: 12 Oct 2005
Posts: 16
:

Items
PostPosted: Sat Oct 22, 2005 9:21 am    Post subject: Ok just to be sure Reply with quote

Thank you! I think I understand, here's an example of each so you can tell me if I'm on the right track:

Test 1: bottom right must be 3 since 12 can be eliminated

12|12
12|123

can 12 be eliminated from the bottom right cell here?

12|12
12|1234

Test2:

12|123
12|123

3s in other cells in the same two houses may be eliminated.

Test3:

12|123
12|124

Look for 34 in one other cell of its house and if found you can remove 34 from the rest of the cells in that house

12|1234
12|1234

Same as above

12|1234
12|1235

Look for 345 in 2 cells of its house and if found remove 345 from the rest of the cells in that house.

Case 4:

Sorry I don't understand case 4. It seems like a guess?
Back to top
View user's profile Send private message
Lummox JR

Joined: 07 Sep 2005
Posts: 202
:

Items
PostPosted: Sat Oct 22, 2005 5:03 pm    Post subject: Re: Ok just to be sure Reply with quote

noeldillabough wrote:
Thank you! I think I understand, here's an example of each so you can tell me if I'm on the right track:

Test 1: bottom right must be 3 since 12 can be eliminated

12|12
12|123

can 12 be eliminated from the bottom right cell here?

12|12
12|1234

Exactamundo. In the first case you can simply place the 3, since it's the only value left. My solver just focuses on the eliminations, though.
Quote:
Test2:

12|123
12|123

3s in other cells in the same two houses may be eliminated.

Yes. Just to clarify, those houses are the box that the 123's share, and the column they share. If you use the B form of this test then they only share a column or row.
Quote:
Test3:

12|123
12|124

Look for 34 in one other cell of its house and if found you can remove 34 from the rest of the cells in that house

12|1234
12|1234

Same as above

12|1234
12|1235

Look for 345 in 2 cells of its house and if found remove 345 from the rest of the cells in that house.

Yes. Note that you could actually find the 345 in all 3 cases. Extra digits are permissible. In the first case if you had 2 extra cells 35 and 45, you still have a partial naked subset.

And of course partial hidden subsets also apply. You have to look for those as well, unless you let your solver go as far as it can when looking for the naked ones. Easiest is to pretend c=34 and d=1234 (for the first and second examples; in the third d=12345), and run it through a subset solver. Then just don't do any eliminations in c or d.
Quote:
Case 4:

Sorry I don't understand case 4. It seems like a guess?

It isn't, although the logic doesn't seem immediately obvious and took me a bit to understand. Case 4 is easiest to understand if you go back to the beginning of the uniqueness test and recall that this layout can never happen unless one of these numbers is a given:
Code:
. 1 .|. 2 .
. . .|. . .
. 2 .|. 1 .

Now if we know ab=12, and if we know the 1 must go in either c or d and nowhere else in the box or line they share, we have at least one of these two scenarios:
Code:
. 1 .|. * .      . 2 .|. 1 .
. . .|. . .      . . .|. . .
. 2 .|. 1 .      . 1 .|. * .

In either case, you can't put a 2 in the asterisked cell because then you have the illegal condition above. So whichever cell is a 1, the other cannot be a 2. c will either be a 1 or it will be a place you cannot put a 2, so 2 cannot go there. The same applies to d. Therefore, 2 can be eliminated from c and d.
Back to top
View user's profile Send private message
noeldillabough

Joined: 12 Oct 2005
Posts: 16
:

Items
PostPosted: Sat Oct 22, 2005 8:29 pm    Post subject: Re: Ok just to be sure Reply with quote

Lummox JR wrote:
noeldillabough wrote:

can 12 be eliminated from the bottom right cell here?

12|12
12|1234

Exactamundo. In the first case you can simply place the 3, since it's the only value left. My solver just focuses on the eliminations, though.


Ah this case above I didn't understand at first, but now with case 4 I see it; if the top right is a 1 the bottom right cannot be a 2, if top right is a 2 the bottom right cannot be a 1.

One question, in this case

12|123
12|123

You said that in case B if they only share a column or row, but if the ab cells share a box and row/col then don't the right cells automatically share two houses? Or is the uniqueness test useable when the ab cells only share a row/col?
Back to top
View user's profile Send private message
Lummox JR

Joined: 07 Sep 2005
Posts: 202
:

Items
PostPosted: Sun Oct 23, 2005 3:13 am    Post subject: Re: Ok just to be sure Reply with quote

noeldillabough wrote:
One question, in this case

12|123
12|123

You said that in case B if they only share a column or row, but if the ab cells share a box and row/col then don't the right cells automatically share two houses?

In the B form, different cells will share two houses. Instead of those being ab and cd, they'd be ac and bd.
Quote:
Or is the uniqueness test useable when the ab cells only share a row/col?

It is, as long as a shares a box with c, and b with d, and they still form the rectangle pattern. This is the B form.
Back to top
View user's profile Send private message
noeldillabough

Joined: 12 Oct 2005
Posts: 16
:

Items
PostPosted: Mon Oct 24, 2005 1:25 pm    Post subject: Reply with quote

I understand now, I mentally pictured both scenarios (ab or ac being the nodes sharing the same box) and labelled them the same way so that a and b were the naked pair.

I have enough to write the code now thank you!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Programming sudoku All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Sudoku Programmers topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group

Igloo Theme Version 1.0 :: Created By: Andrew Charron