|
View previous topic :: View next topic |
Author |
Message |
| Tempbow
| Joined: 18 Apr 2005 | Posts: 22 | : | | Items |
|
Posted: Mon Apr 18, 2005 12:02 pm Post subject: Representation matrices for puzzle analysis |
|
|
I was playing around with a program to show a puzzle during its resolution process. Normally I display the 9x9 matrix with the list of possibles in each cell. The aim, of course, is to reduce this matrix via logic rules so it contains just the 81 elements of a resolved puzzle. A possibles matrix may look like this:
Code: | SUDOKU contains:
.8...3.6.
.3.....1.
.975..38.
....9.2..
..8.7.4..
..3.6....
.16..289.
.49....2.
.521.964.
|
POSSIBLE ENTRIES:
Code: |
1245 8 145 479 124 3 579 6 24579
2456 3 45 46789 248 4678 579 1 24579
1246 9 7 5 124 46 3 8 24
145 67 145 348 9 1458 2 357 168
159 26 8 23 7 15 4 35 169
1459 27 3 248 6 1458 19 57 189
37 1 6 47 345 2 8 9 357
378 4 9 678 358 678 157 2 1357
378 5 2 1 38 9 6 4 37
|
=====
Reduction target is 81, value is 180
We see that there are still 99 reductions to make to solve this puzzle.
The analysis I have found involves expressing this same information in a different way. We build two new 9x9 matrices, one for a row analysis and another for a column analysis. The row analysis displays for each possible (1-9) the position within each row where that possible occurs.
So cell (1,1) will contain the positions where 1 can possibly occur in row 1
and cell (1,2) will contain the positions where 2 can occur in row 1.
The column analysis builds a similar matrix, but looking at the locations of possibles by column rather than row. The resulting matrices have interesting properties, allowing a quicker discovery of such familiar patterns as XWING (see 24 24 and 48 48 and 29 29 and 28 28 for 4 examples below) and SWORDFISH. For the above example, the row and column analyses are as shown here:
ROWS ANALYSIS possibles 1 - 9
Code: |
1 2 3 4 5 6 7 8 9
135 159 6 13459 1379 8 479 2 479
8 159 2 134569 1379 146 4679 456 479
15 159 7 1569 4 16 3 8 2
1369 7 48 1346 1368 29 28 469 5
169 24 48 7 168 29 5 3 19
1679 24 3 146 168 5 28 469 179
2 6 159 45 59 3 149 7 8
79 8 159 2 579 46 14679 1456 3
4 3 159 8 2 7 19 15 6
|
COLUMNS ANALYSIS possibles 1 - 9
Code: |
1 2 3 4 5 6 7 8 9
13456 123 789 12346 12456 23 789 89 56
7 56 2 8 9 45 46 1 3
14 9 6 124 124 7 3 5 8
9 56 45 12467 3 28 1278 2468 12
13 123 789 1237 78 6 5 289 4
456 7 1 2346 456 238 28 2468 9
68 4 3 5 128 9 128 7 126
2 8 45 9 456 1 46 3 7
4568 123 789 123 1278 45 12789 46 1256
|
At this stage I have merely produced these analyses, without developing any code around them. But they look like promising representations.
The 3rd obvious representation would be by box, so that the 9 rows of the analysis would represent the possibles positioned by top left box, top centre box, top right box etc through to the bottom right box.
However, I suspect that the column and box analyses have nothing to add over just one analysis, such as the row analysis.
Comments welcome.
Terry |
|
Back to top |
|
|
| rubylips
| Joined: 07 Apr 2005 | Posts: 62 | : | Location: London | Items |
|
Posted: Mon Apr 18, 2005 2:00 pm Post subject: |
|
|
I agree with your basic claim that it's critical to store several state grids if we are to achieve maximum performance. My Java solver solves all 3x3 puzzles - even those that require guesses - in a fraction of a second. Much of its speed stems from its use of three different state grids:
Cell State - boolean[Row][Column][Value] - which stores whether Value is a candidate for the cell (Row,Column).
It's worthwhile to maintain a related matrix int[Row][Column] which stores the number of Values for which the Cell State is true.
Number State - boolean[Value][Sector][Element] - where Sector is a row, column or box, so there are 3*(# Cells In Row) possibilities, and Element is the offset within the Sector of the given cell. Effectively, we characterize a given cell according to Sector and Element rather than Row and Column (of course, there will be three (Sector, Element) descriptions for each cell), but we will achieve dramatic performance improvements in places.
It's worthwhile to maintain a related matrix int[Value][Sector] which stores the number of Values for which the Number State is true.
Information State (actually my source calls it Invulnerable State but Information State would have been a far better name) - int[Value][Row][Column] which is difficult to describe - I'll add a topic at some point - but is critically important in order to compose problems and to guess.
Of course, since we have three state grids, it will take us longer to update state when an elimination is made but it's clearly time well spent. |
|
Back to top |
|
|
|
|
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
|
Powered by phpBB © 2001, 2005 phpBB Group
Igloo Theme Version 1.0 :: Created By: Andrew Charron
|