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   

Starting over

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

Joined: 14 Dec 2005
Posts: 26
:

Items
PostPosted: Fri Dec 16, 2005 3:36 pm    Post subject: Starting over Reply with quote

It's kinda hard to program a technique that you don't really understand and I'm not one to lift code so.... I have to start over and get this right in my brain of how dancing links work.

I did some reading on Wikipedia on the dancing links algorithm.
Quote:
it links together cells in a grid and then modifies the links in a complex but ordered way until a solution is found.

I definitely know what lists are. Doubly linked lists to me look like a two way road where you can back up or move forward 1 space from the target cell. I see arrays being used as doubly linked lists.

Quote:
The most common application of Dancing Links is to solving Sudoku puzzles. The puzzle is represented as a matrix with 324 columns and up to 729 rows. Each row represents the option of placing the digit d into the cell (r,c).

The 324 columns are divided into 4 groups of 81:

The first group represents the cell (r,c) being filled;
The second group represents the digit d being placed into row r;
The third group represents the digit d being placed into column c;
The fourth group represents the digit d being placed into block b (b is a function of r and c).
Each row will have exactly 4 ones and 320 zeros.


The 729 looks to be coming from 81 cells * 9 candidates per cell = 729. I can understand that no problem *IF* thats what they mean.

The 329 apparently represents the cells (81), rows(81), columns(81), and boxes(81). It looks like this doesn't take into account the candidates but only valid answers (completed). When all cells have valid numbers it will equal 81, likewise with rows, columns, and boxes.

A diagram:
Code:

             Columns
    1 2 3 | 4 5 6 | 7 8 9
    4 5 6 | 0 0 0 | 0 0 0
R   7 8 9 | 0 0 0 | 0 0 0
o   ------+-------+------
w   C 0 0 | 0 0 0 | 0 0 0
s   0 0 0 | B O X | 0 0 0
    0 0 0 | 0 0 0 | 0 0 0

C=Cell


Traditionally I've always used X,Y or Column,Row for about everything I've done in programming. But it appears that Row,Column is being used for this. No problem I can adapt. Razz

Btw, kinda wish I had just registered with my real name, Anthony. King Wonka is kind of adolescent. Anyhow, if you have time to add to my quest for understanding dancing links feel free to theorize with me.

edit: What exactly composes a Subset?

Anthony
Back to top
View user's profile Send private message
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

Items
PostPosted: Fri Dec 16, 2005 3:55 pm    Post subject: Reply with quote

Hi Anthony,

I've placed an explanation of Dancing Links here:
http://home.quicknet.nl/qn/prive/r.vanderwerf/dancinglinks.htm

It may give you some ideas about setting up the data structures.

Ruud.
_________________
Meet me at sudocue.net
Back to top
View user's profile Send private message Visit poster's website
Bob Hanson

Joined: 05 Oct 2005
Posts: 187
:
Location: St. Olaf College

Items
PostPosted: Fri Dec 16, 2005 4:29 pm    Post subject: Reply with quote

Ruud, I think with your help I could understand this.

I read:

The viewer shows all 324 constraints that must be met. In terms of Dancing
Links, these are the columns. With an empty grid, there are 9 candidates
competing in each of these constraints. A candidate is a particular digit
assigned to a cell. Each candidate must fight for its existence in each of the 4
major areas. When it loses in one of them, it is removed from all 4 areas.
The candidates are represented by a blue rectangle in each of the 4 areas.
When a constraint has declared a winner, that candidate will be shown in
green.

But then on the left there is a list of Row numbers instead of digits, and I
guess I don't understand that histogram. Why are there multiple blue
boxes in a vertical stack?

Could you just read across the top row and say what that means?


Maybe just show us the configuration corresponding to this.

Thanks.
_________________
Bob Hanson
Professor of Chemistry
St. Olaf College
Northfield, MN
http://www.stolaf.edu/people/hansonr
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

Items
PostPosted: Fri Dec 16, 2005 5:37 pm    Post subject: Reply with quote

The first stack shows the "cell" constraints.
- Cells are identified by Row (side) and Column (top).

The next 3 stacks show the "unit" constraints, rows, columns and boxes.
- Units are identified by number (top) and digit (side)

Each constraint has upto 9 candidates. These are represented by the blue boxes. There is not enough room to show which candidates, but you always have the main Sudo Cue window that shows the remaining candidates.

When a constraint has only one box, it is green, and the constraint is "solved" or "satisfied". When there are 2 blue boxes in a constraint, there are 2 candidates remaining. So, in the example, Row 1 and 5 have 2 candidates for digit 1, row 6 has 3 candidates left.

There is no connection between constraint groups which are side-by-side. However, when you look at the last 3 stacks, you can see how each digit is solved in the 27 unit constraints. The total number of candidates per digit is the same for rows, columns and boxes.

So,

this is not the full columns and rows as used by DLX. It is a condensed visualization. The full DLX grid has 729 rows. That would leave 1 pixel per row. And I would have to place all 324 constraints side-by-side. Not enough room to be informative. This condensed view shows only the nodes that are actually used.

Ruud.
_________________
Meet me at sudocue.net
Back to top
View user's profile Send private message Visit poster's website
Bob Hanson

Joined: 05 Oct 2005
Posts: 187
:
Location: St. Olaf College

Items
PostPosted: Fri Dec 16, 2005 5:41 pm    Post subject: Reply with quote

Ah, OK. But there is room -- why not just color the box of the specific
candidate blue rather than stacking them? Actually, I think this would be
REALLY nice, because you would instantly see the naked tuples,
X-Wings and such right there in front of you.
_________________
Bob Hanson
Professor of Chemistry
St. Olaf College
Northfield, MN
http://www.stolaf.edu/people/hansonr
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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