June 12, 2006 at 3:04 pm
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/dpoole/sqlsudoko.asp
June 22, 2006 at 2:33 am
This is not the first TSQL Sudoku puzzle solver/generator (see, for example The Sudoku Puzzle Generator. However, it is nicely explained. The two approaches are completely different. Perhaps, with Phil's puzzle generator and this solver, a SQL Server system could keep itself amused for ever!
June 22, 2006 at 2:56 am
Other sql soduko's:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50372
Nice job David P. 🙂
rockmoose
You must unlearn what You have learnt
June 22, 2006 at 7:46 am
I'm not a fan of Sudoko, but I really enjoyed this article. Good work!
John Scarborough
MCDBA, MCSA
June 22, 2006 at 8:12 am
I like Sudokus, the hard one's particularly. Couple of observations :
1) Very nice and all, but perhaps you have a little too much time on your hands?
2) Slippery little algorithms for Sudokus aren't they? I'd never made the relationship between them and SQL server, I'm thinking they're good brain food for coding....
All in all, impressive, but pointless
Keep up the good work...
June 22, 2006 at 8:52 am
I think this is great and plan on spending the next two weeks testing ! Who cares if all the other applications I support go down ... I'll be busy testing
June 22, 2006 at 9:25 am
I think I am missing something. I have done all the code but it is not working right for me.
June 22, 2006 at 1:54 pm
Two things are missing as far as I can see.
There is no CREATE-statement for the Sudoko table. But since the schema for the table is shown, it is trivial to put this in:
IF EXISTS (SELECT * FROM sys.tables WHERE Name='Sudoko')
DROP TABLE Sudoko
CREATE TABLE Sudoko (
RowId TinyINT NOT NULL,
ColumnID TinyINT NOT NULL,
CellValue TinyINT NULL,
CONSTRAINT pk_sudoko PRIMARY KEY (RowID, ColumnID)
)
A more serious problem occurs at the end of the final implementation of SolveSingleCells - where the sp calls the procedure RemoveSolvedCells. This procedure is not defined anywhere in the article.
Regards
Jens Gyldenkærne Clausen
June 22, 2006 at 2:11 pm
Nice job. Now I don't feel so silly for writing a FORTH interpreter in T-SQL.
jg
June 22, 2006 at 2:44 pm
Phil Factor's solution that I mentioned earlier in the thread uses the same approach as the one Joe Celco mentions that he uses. It is, as he says, far neater. The Wikipedia entry on Sudoku is excellent. It does touch on the various computer approaches to constructing and solving the puzzle Sudoku in the Wikipedia
June 22, 2006 at 4:21 pm
I noticed the same things too.
Creating the table sudoko was pretty trivial.
Of greater concern is the missing RemoveSolvedCells SP.
Also, since I am using MS SQL Server 2000, I had to change all the "sys.views," "sys.tables," "sys.procedures," etc. to sysobjects.
Some way to print out the unsolved and solved puzzle in a user readable format would be a nice addition. Something that looks like this:
START
*-----------*
|...|5.8|.47|
|84.|...|..2|
|...|64.|...|
|---+---+---|
|.6.|1..|57.|
|..7|...|.16|
|..4|.3.|.8.|
|---+---+---|
|73.|...|...|
|..2|...|...|
|...|9.4|1..|
*-----------*
SOLVED
*-----------*
|623|518|947|
|841|397|652|
|975|642|831|
|---+---+---|
|368|129|574|
|297|485|316|
|154|736|289|
|---+---+---|
|739|251|468|
|412|863|795|
|586|974|123|
*-----------*
June 23, 2006 at 3:34 am
I think I may have found a puzzle that this one doesn't solve. (Though it could just be that my implementation is wrong.)
x84|x6x|xxx
x9x|xxx|x7x
3xx|xx2|x5x
---+---+---
xxx|7xx|38x
xxx|2x5|xxx
x27|xx1|xxx
---+---+---
x1x|9xx|xx4
x3x|xxx|x1x
xxx|x1x|56x
I found this puzzle at http://www.websudoko.com
June 23, 2006 at 5:09 am
Can I get someone that has gotten this to work upload their code or something so that I can verify it with my code? My code is not working correctly.
Thanks
June 23, 2006 at 6:10 am
My apologies for the missing stored procedure.
When I started building my solution I prototyped it by bouncing values through tables and the procedure was used to remove solved cells from a working table.
Of course once I worked out how to do the entire thing using views the procedure became redundant.
There is a form of Sudoko that I have seen called Ariadne's thread.
Ariadne is the person who supplied a Greek hero (Perseus?) with a thread so he could find his way around the Minotaur's labyrynth.
With this form of Sudoko you will reach a point where a decision has to be made between 2 values in a particular cell. Choose the wrong value and the puzzle won't solve, therefore you have to retrace your steps until you can fill in the alternative value.
Obviously, this T-SQL solution will not cater for this type of puzzle.
June 23, 2006 at 7:57 am
First off, cool article
I'm also using SQL 2000, so instead of using sys.views I use:
IF object_id('Digits') is not null drop view Digits
Here is a way to print the Sudoko table using SQL 2000. You need to change the options in query analyzer to not print column headers and set the output format to "space delimited".
select '*','-','-','-','-','-','-','-','-','-','-','-','*'
union all
select --rowId
'|'
,max(case columnId when 1 then isnull(cast(cellValue as char(1)),'.') end)
,max(case columnId when 2 then isnull(cast(cellValue as char(1)),'.') end)
,max(case columnId when 3 then isnull(cast(cellValue as char(1)),'.') end)
,'|'
,max(case columnId when 4 then isnull(cast(cellValue as char(1)),'.') end)
,max(case columnId when 5 then isnull(cast(cellValue as char(1)),'.') end)
,max(case columnId when 6 then isnull(cast(cellValue as char(1)),'.') end)
,'|'
,max(case columnId when 7 then isnull(cast(cellValue as char(1)),'.') end)
,max(case columnId when 8 then isnull(cast(cellValue as char(1)),'.') end)
,max(case columnId when 9 then isnull(cast(cellValue as char(1)),'.') end)
,'|'
from sudoko
where rowId 6
group by RowId
union all
select '*','-','-','-','-','-','-','-','-','-','-','-','*'
Viewing 15 posts - 1 through 15 (of 24 total)
You must be logged in to reply to this topic. Login to reply