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   

Killer Swordfish example
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Solving sudoku
View previous topic :: View next topic  
Author Message
IJ

Joined: 15 Apr 2005
Posts: 16
:

Items
PostPosted: Mon Apr 18, 2005 2:15 pm    Post subject: Reply with quote

Yes, a Jacko! Rubylips and I had a debate about what Nishio was on the previous incarnation of this site, I thought it was a pattern based resolution (as per all the other known methods), Rubylips thought it was a technique of focussed T&E. To avoid confusion, and to stop having the argument, we ended up deciding that I'd get to name the pattern, and I chose "Jacko". I could start another thread to discuss it if you're interested, though I've only ever seen one puzzle where it came up...
Back to top
View user's profile Send private message
Simes

Joined: 08 Apr 2005
Posts: 71
:
Location: North Yorkshire, UK

Items
PostPosted: Mon Apr 18, 2005 2:25 pm    Post subject: Reply with quote

Well I never did get my head around Nishio, and I'm still struggling to understand the reasoning behind swordfish.

Is the jacko similarly complex?
Back to top
View user's profile Send private message Visit poster's website
rubylips

Joined: 07 Apr 2005
Posts: 62
:
Location: London

Items
PostPosted: Mon Apr 18, 2005 2:36 pm    Post subject: Reply with quote

You're completely right about the elimination of the 7 in (1,1) - a recent 'performance enhancement' Embarassed in my code (unrelated to Swordfish) led me to miss this. (The code ran very fast, though!)

Let's forget that example entirely.
Back to top
View user's profile Send private message Visit poster's website
IJ

Joined: 15 Apr 2005
Posts: 16
:

Items
PostPosted: Mon Apr 18, 2005 2:55 pm    Post subject: Reply with quote

Well, the Jacko only involves 4 digits, but their relationship is a little complex - I'll start a new thread rather than muddy this one.

The way I convince myself that the swordfish is right is by thinking of it as a staircase:

A * * D
* * C d
* B c
a b

You need all the columns and at least one of the rows to have only two places for the given digit. The columns are as shown, and let's say it's the bottom row that has only two places (a & b).

So, starting from the bottom, and going anti-clockwise, say a=true (has the digit), this means that b=false, so B=True, so c=false, C=True, d=False, D=True.

To show what happens when a=false, start in the same place, but go the other way, so A=true, D=false, d=True, C=False, c=True, B=False, b=True.

In both cases we have shown that one of the two places on each row must be true (e.g. B or c, C or d), so that digit can't appear elsewhere on the row.

It's a small leap from there to convince yourself that it doesn't actually need to look like a stair case to work, and it doesn't matter which of the rows has only two instances.

Hope this helps, though I suspect it might just confuse things further...

PS Rubylips - don't worry - we've all been there!
Back to top
View user's profile Send private message
AMcK

Joined: 07 Apr 2005
Posts: 89
:
Location: Cambridge

Items
PostPosted: Wed Apr 20, 2005 6:01 pm    Post subject: Reply with quote

So this is where you're all lurking now!

Colouring also seems to work OK on killer swordfish and prime suspect

Here's Prime Suspect
Code:

35   18   35   4   7   9   6   2   18
178   178   4   26   26   18   3   9   5
9   2   6   35   18   35   148   47   1478
57   3   1   257   248   578   45   6   9
258   48   25   9   3   6   145   47   147
567   467   9   157   14   157   2   8   3
23   5   23   8   9   4   7   1   6
4   16   8   37   16   37   9   5   2
16   9   7   16   5   2   48   3   48


Conjugate row: digit 1 cells {1,2} {1,9}
Colour: {1,2} (a) {1,9} (b)
Conjugate row: digit 1 cells {5,7} {5,9}
Colour: {5,7} (c) {5,9} (d)
Conjugate row: digit 1 cells {8,2} {8,5}
Colour: {8,2} (e) {8,5} (f)
Conjugate row: digit 1 cells {9,1} {9,4}
Colour: {9,1} (g) {9,4} (h)
Conjugate column: digit 1 cells {2,1} {9,1}
Colour: {2,1} (h) {9,1} (g)
Conjugate column: digit 1 cells {6,4} {9,4}
Colour: {6,4} (g) {9,4} (h)
Conjugate column: digit 1 cells {2,6} {6,6}
Colour: {2,6} (i) {6,6} (j)
Conjugate column: digit 1 cells {3,7} {5,7}
Colour: {3,7} (d) {5,7} (c)
Conjugate box: digit 1 cells {2,6} {3,5}
Colour: {2,6} (i) {3,5} (j)
Conjugate box: digit 1 cells {5,7} {5,9}
Colour: {5,7} (c) {5,9} (d)
Conjugate box: digit 1 cells {8,2} {9,1}
Recolour: {2,1} (h->e)
Recolour: {6,4} (g->f)
Recolour: {9,1} (g->f)
Recolour: {9,4} (h->e)
Colour: {8,2} (e) {9,1} (f)
Conjugate box: digit 1 cells {8,5} {9,4}
Conjugate column: digit 1 cells {3,7} {5,7}
Colour: {3,7} (d) {5,7} (c)
Conjugate box: digit 1 cells {2,6} {3,5}
Colour: {2,6} (i) {3,5} (j)
Conjugate box: digit 1 cells {5,7} {5,9}
Colour: {5,7} (c) {5,9} (d)
Conjugate box: digit 1 cells {8,2} {9,1}
Recolour: {2,1} (h->e)
Recolour: {6,4} (g->f)
Recolour: {9,1} (g->f)
Recolour: {9,4} (h->e)
Colour: {8,2} (e) {9,1} (f)
Conjugate box: digit 1 cells {8,5} {9,4}
Colour: {8,5} (f) {9,4} (e)
Non-conjugates: row 2 colours e i
Non-conjugates: row 3 colours j d
Non-conjugates: row 6 colours f j
Non-conjugates: column 2 colours a e
Non-conjugates: column 5 colours j f
Non-conjugates: column 9 colours b d
Non-conjugates: box 1 colours a e
Non-conjugates: box 3 colours b d
Non-conjugates: box 5 colours f j
Mutual exclusion: colours e/f i/j
Recolour: {2,6} (i->f)
Recolour: {3,5} (j->e)
Recolour: {6,6} (j->e)

Colouring for digit: 1
Code:

.   a   .   .   .   .   .   .   b
e   .   .   .   .   f   .   .   .
.   .   .   .   e   .   d   .   .
.   .   .   .   .   .   c   .   d
.   .   .   f   .   e   .   .   .
.
.   e   .   .   f   .   .   .   .
f   .   .   e   .   .   .   .   .

Hence
Row 2 reduction: digit 1 colours e/f cell {2,2} before 178 after 78
Row 6 reduction: digit 1 colours f/e cell {6,5} before 14 after 4

Reduced grid
Code:

35   18   35   4   7   9   6   2   18
178   78   4   26   26   18   3   9   5
9   2   6   35   18   35   148   47   1478
57   3   1   257   248   578   45   6   9
258   48   25   9   3   6   145   47   147
567   467   9   157   4   157   2   8   3
23   5   23   8   9   4   7   1   6
4   16   8   37   16   37   9   5   2
16   9   7   16   5   2   48   3   48


Easy from then on
Best regards
Andrew
Back to top
View user's profile Send private message Send e-mail
AMcK

Joined: 07 Apr 2005
Posts: 89
:
Location: Cambridge

Items
PostPosted: Wed Apr 20, 2005 9:56 pm    Post subject: Programming colouring/swordfish Reply with quote

What I like about the colouring algorithm is that there is no complex reasoning - it just colours the conjugate pairs in complementary colours then gradually simplifies the colour map by discovering that colours are identical. Here are the relevant steps leading to the two reductions in Prime Suspect.
Starting from
Code:

35    18    35    4     7     9     6     2     18
178   178   4     26    26    18    3     9     5 
9     2     6     35    18    35    148   47    1478
57    3     1     257   248   578   45    6     9 
258   48    25    9     3     6     145   47    147
567   467   9     157   14    157   2     8     3 
23    5     23    8     9     4     7     1     6 
4     16    8     37    16    37    9     5     2 
16    9     7     16    5     2     48    3     48


In row 8
{8,2} and {8,5} are a conjugate pair
{8,2}=e, {8,5}=f
In row 9
{9,1} and {9,4} are a conjugate pair
{9.1}=g, {9,4}=h
In column 1
{2,1} and {9,1} are a conjugate pair
Already {9,1}=g
Therefore {2.1}=h
In column 4
{6,4} and {9,4} are a conjugate pair
Already {9,4}=h
Therefore {6,4}=g
In column 6
{2,6} and {6,6} are a conjugate pair
{2,6}=I, {6,6}=j
In box 7
{8,2} and {9,1} are a conjugate pair
Already {8,2}=e, {9,1}=g
Therefore e/f = h/g
So recolour {2,1}=e
In box 2
{2,6}, {3.5} are a conjugate pair
Already {2,6}=i
Therefore {3,5}=j
In row 2
{2,1}=e excludes {2,6}=i
In row 6
{6,4}=f excludes {6,6}=j
Therefore e/f = i/j
So recolour {2,6}=f, {6,6}=e
In row 2
We have proved {2,1}=e and {2,6}=f are conjugate
We may now eliminate 1 from {2,2}
In row 6
We have proved that {6,4}=f and {6,6}=e are conjugate
We may now eliminate 1 from {6,5}

The algorithm therefore shows by serial reasoning that two of the cells in rows 2 and 6 are in fact conjugate either/or pairs which preclude 1's in any other cells.

Programming the algorithm is easy:

1. Scan all the rows/columns/boxes for each digit to colour conjugate pairs
2. Scan all the rows/columns/boxes for colour exclusions and identities
3. Scan all the rows/columns/boxes for conjugate colour pairs and reductions

Until I come across a puzzle that colouring solves by swordfish does't I'll believe that it's just a more mechanical way to reach the same conclusion as Rubylips - much more like the 3 rules.
Hope that clarifies.
Regards, Andrew
Back to top
View user's profile Send private message Send e-mail
rubylips

Joined: 07 Apr 2005
Posts: 62
:
Location: London

Items
PostPosted: Wed Apr 20, 2005 11:48 pm    Post subject: Reply with quote

Does the Colouring Algorithm cope with the four Nishio examples that appear in the '(My) Nishio definition' topic?
Back to top
View user's profile Send private message Visit poster's website
AMcK

Joined: 07 Apr 2005
Posts: 89
:
Location: Cambridge

Items
PostPosted: Thu Apr 21, 2005 8:05 am    Post subject: Colouring, Nishio and slicing Reply with quote

Sadly, colouring isn't able to find any reductions in your new set of 4 Nishio patterns - with the old easy pattern 3 removed, the old 4 renamed as 3 and a new 4th. It doesn't surprise me on reflection because colouring is merely a generalisation of X-Wings and an alternative method for swordfish and cannot therefore do "what if" lookahead like Nishio. I need to look much harder at your Nishio examples to see if there's a colouring method that might legitimise its single-step breadth-first "guessing" approach. However, I am doubtful.

There's another approach I've been working on. I'll have to put it down for a few days because of some urgent paid work so I'll share it tentatively.

Clearly it is not feasible to enumerate all possible valid and completed suduko 9x9 grids. However, is is feasible to enumerate all possible valid 3x9 slices, if you assume that box 1 is
123
456
789
and that slices for other values in box 1 can be derived by simple 1..9 renumbering. I have generated all 2,612,736 of them in an 285MB Access database. (In fact, there are less if you take advantage box 2/3 symmetries but I haven't grappled with that yet).

A possible solution method would then be to simply search the database for a set of 6 interlocking 3x9 patterns that, when renumbered, match the puzzle. Using SQL alone, I can now match completed puzzles in a few seconds. I know how to program the matching of partial puzzles but have no idea of potential speed, either with SQL or in-memory indexing.

Clearly, the legitimacy of this method is dubious and offers no hope for a new manual technique. Although it requires some database searching because it's using the 3x9 slice space optimisation, it isn't guessing in the conventional sense, since it already knows all the solutions and is simpy trying to match them to the puzzle. I'll keep you posted.

Andrew
Back to top
View user's profile Send private message Send e-mail
coconut

Joined: 13 May 2005
Posts: 12
:
Location: Oxford

Items
PostPosted: Mon May 16, 2005 8:27 am    Post subject: killer swordfish Reply with quote

In the (second, so far undisputed) killer swordfish example of rubylips, my program indicates an x-wing followed by anothe x-wing. My numbering is (column,row) which is the standard in mathematics (linear algebra and matrix theory). After some standard processing by my program,

number 7 is mutually exclusive to (3,8) and (3,9)
number 7 is mutually exclusive to (3,8) and (5,8)
number 7 is mutually exclusive to (3,9) and (5,9)

Thus number 7 can be eliminated from (5,1) and (5,2)

This in turn gives an another x-wing

number 7 is mutually exclusive to (2,1) and (2,2)
number 7 is mutually exclusive to (2,2) and (6,2)
number 7 is mutually exclusive to (6,1) and (6,2)

Thus number 7 is not present in (4,1) which gives number 5 as the occupant of (4,1).

If you dont get these x-wings, then I am doing a step which is not in your programs.

coconut
Back to top
View user's profile Send private message
coconut

Joined: 13 May 2005
Posts: 12
:
Location: Oxford

Items
PostPosted: Mon May 16, 2005 1:33 pm    Post subject: Reply with quote

I am so sorry; my numbering is (row,column).

coconut
Back to top
View user's profile Send private message
Animator

Joined: 26 Apr 2005
Posts: 18
:

Items
PostPosted: Mon May 16, 2005 3:53 pm    Post subject: Reply with quote

You don't really need an X-wing to exclude the 7's from r5c1 and r5c2. If you look at box 6, then you will see that the only possible place for a 7 is on row5. Yes there is an X-wing too (or atleast in theory) but it's irrelevant.

Also, I'm currently re-solving it, and my first question is: why did you exclude the 7 from r4c1?

And, why do you say: 'number 7 is mutually exclusive to (6,1) and (6,2)' ? A 7 can occur in r6c1, r6c2, r6c4 and r6c6...
Back to top
View user's profile Send private message
coconut

Joined: 13 May 2005
Posts: 12
:
Location: Oxford

Items
PostPosted: Tue May 17, 2005 2:03 pm    Post subject: swordfish example of rubylips Reply with quote

Animator is right and I was wrong; (a) I cant exclude 7 from r4c1 and (b) 7 can occur in r6c1, r6c2, r6c4 and r6c6.

Is there a rule book with fomal definitions (e.g. for x-wing, swordfish) which can be used to justify any step?
Back to top
View user's profile Send private message
Tempbow

Joined: 18 Apr 2005
Posts: 22
:

Items
PostPosted: Wed May 18, 2005 11:16 am    Post subject: Re: swordfish example of rubylips Reply with quote

coconut wrote:
Animator is right and I was wrong; (a) I cant exclude 7 from r4c1 and (b) 7 can occur in r6c1, r6c2, r6c4 and r6c6.

Is there a rule book with fomal definitions (e.g. for x-wing, swordfish) which can be used to justify any step?


Although not my own definition, but one I noted down from an earlier forum -

Look for N columns (2 for X-wing, 3 for the Swordfish, 4 for a Jellyfish, 5 for a Squirmbag) with only two candidate cells for ONE given digit. If these fall on exactly N common rows, and each of those rows has at least 2 candidate cells, then all N rows can be cleared of that digit (except in the defining cells!).

To complete the definition, interchange columns and rows in the above.

Terry
Back to top
View user's profile Send private message
coconut

Joined: 13 May 2005
Posts: 12
:
Location: Oxford

Items
PostPosted: Fri May 20, 2005 8:03 am    Post subject: Reply with quote

Are there problems which can be solved only via jellyfish or squirmbag (without nishio, of course) ?

coconut
Back to top
View user's profile Send private message
AMcK

Joined: 07 Apr 2005
Posts: 89
:
Location: Cambridge

Items
PostPosted: Fri May 20, 2005 9:01 am    Post subject: X-wing, Swordfish, Jellyfish and Colouring Reply with quote

Thanks for the definitions of X-wing, Swordfish, Jellyfish, Squirmbag ...

Look for N columns (2 for X-wing, 3 for the Swordfish, 4 for a Jellyfish, 5 for a Squirmbag) with only two candidate cells for ONE given digit. If these fall on exactly N common rows, and each of those rows has at least 2 candidate cells, then all N rows can be cleared of that digit (except in the defining cells!).

As stated, they form a 3-level hierarchy sitting above the traditional 3 rules. However, there may be quite different methods of logical analysis just waiting to be discovered that cut across this hierarchy.

It seems to me that colouring is a superset of all of these - and more - because it analyzes ALL the relationships threads between conjugate pairs of candidates in rows, columns and boxes, no matter how long and convoluted they may be. X-wing, Swordfish, Jellyfish and Squirmbag all limit themselves to regular row/column configurations of conjugate pairs.

Do you have examples of Jellyfish and Squirmbag that I could use to check the colouring solver? It would be good to convince myself.

AMcK
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Solving sudoku All times are GMT
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
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