| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: It was very romantic |
"Ian" wrote in message
news:1109811970.234440.131940{at}g14g2000cwa.googlegroups.com...
> Actually I don't need to write it. I've managed to simulate the flow,
> using Not existing selects as cdrs.
>
> If I do this, I end up with, in pure Lisp style, everything done in a
> single command.
>
> "Delete B From Box B Where Exists (Select * From Box Z Where B.V = Z.V
> And (B.C Z.C Or B.R Z.R) And (B.R = Z.R Or B.C = Z.C
Or B.Box =
> Z.Box) And Not Exists (Select * from Box F Where F.R = Z.R And F.C =
> Z.C And F.V Z.V)) Or Exists (Select * From Box B2 Where B2.R = B.R
> And B2.C = B.C And B2.V B.V And (Not Exists (Select * From Box B3
> Where B2.R = B3.R And B3.C B2.C And B2.V = B3.V) Or Not Exists
> (Select * From Box B3 Where B2.C = B3.C And B3.R B2.R And B2.V =
> B3.V) Or Not Exists (Select * From Box B3 Where B2.Box = B3.Box And
> (B2.R B3.R Or B3.C B2.C) And B2.V = B3.V)))"
>
> It even has Lots of Silly Parentheses.
That is the aspect of lisp that tends to do my head in - i.e. it seems to
encourage inordinate nesting via the use of parentheses. I used to write a
lot of heavilly nested code myself in earlier years but after being
contracted to read others code similarly nested I started using other code
writing strategies to make it easier to follow and read. Of course the
example you gave above isn't really that bad at all having only three levels
of nesting at max but when it comes to lisp 'in the wild' I have seen some
really mind boggling nesting depths!
>
> Of course there's lots more clever ways the soduko puzzles could be
> complicated, such as adding further levels of induction in order to
> determine for certain, a particular step.
>
> This one above only solves the typical cases where deduction is all you
> need.
>
>
>
---------------------------------------------------------------------------------------
> All the rest of the code is setting the data up. The single instruction
> above (repeatedly called) solves the soduko. In the lisp it would of
> course repeatedly iterate itself.
Interesting use of database tables and procedures to solve mathematical type
puzzles - of course this gives you some advantages over a purely 'array'
based solution having at your disposal the 'select' commands and union
functions etc. Thanks for your time and effort - I still have not yet got my
head into suduku's (distracted by my current focus on hardware etc) but it
would be an interesting excercise to see if I could achieve the same with a
purely array based scheme - at this stage I don't know if such solutions
would be possible but it would be interesting to find out.
Perhaps you have already investigated that route but found that where you
have a dbms engine to exploit you might as well get the 'best of both
worlds'.
In any case your code examples are a definite keeper if only for those
'slow' nights when I have too much caffeine in my blood and doing a few
crosswords just won't suffice! :-o)
Phil
>
> use Test
> Drop View SQ
> Drop Table dbo.Box
> Drop Procedure dbo.spSudokuInitRow2
> Drop Procedure dbo.spSudokuInitBox2
> Drop Procedure dbo.spViewAll2
> Go
> Create View SQ As Select Val = 1 Union Select Val = 2 Union Select Val
> = 3 Union Select Val = 4 Union Select Val = 5 Union Select Val = 6
> Union Select Val = 7 Union Select Val = 8 Union Select Val = 9
> Go
> Create Table dbo.Box (R TinyInt, C TinyInt, V TinyInt, Box As 3 * ((R -
> 1) / 3) + (C - 1) / 3 + 1)
> Go
> Create Procedure dbo.spSudokuInitRow2 {at}R TinyInt, {at}Data Char (9) As
> Begin
> Declare {at}C TinyInt, {at}Ch Char (1), {at}V TinyInt
> Set {at}C = 1
> While {at}C <= 9 Begin
> Set {at}Ch = Substring ({at}Data, {at}C, 1)
> If {at}Ch in ('1', '2', '3', '4', '5', '6', '7', '8', '9') Delete Box
> Where R = {at}R And C = {at}C And V Convert (TinyInt, {at}Ch)
> Set {at}C = {at}C + 1
> End
> End
> Go
> Create Procedure dbo.spSudokuInitBox2 {at}Row1 Char(9), {at}Row2 Char(9),
> {at}Row3 Char(9), {at}Row4 Char(9), {at}Row5 Char(9), {at}Row6 Char(9), {at}Row7
> Char(9), {at}Row8 Char(9), {at}Row9 Char(9) As Begin
> Set NoCount On
> Delete dbo.Box
> Insert Box Select S1.Val, S2.Val, S3.Val From SQ S1, SQ S2, SQ S3
> Exec dbo.spSudokuInitRow2 1, {at}Row1
> Exec dbo.spSudokuInitRow2 2, {at}Row2
> Exec dbo.spSudokuInitRow2 3, {at}Row3
> Exec dbo.spSudokuInitRow2 4, {at}Row4
> Exec dbo.spSudokuInitRow2 5, {at}Row5
> Exec dbo.spSudokuInitRow2 6, {at}Row6
> Exec dbo.spSudokuInitRow2 7, {at}Row7
> Exec dbo.spSudokuInitRow2 8, {at}Row8
> Exec dbo.spSudokuInitRow2 9, {at}Row9
> End
> Go
> Create Procedure dbo.spViewAll2 As Begin
> Set Nocount On
> Declare {at}R TinyInt, {at}Strn Varchar (3000), {at}C TinyInt, {at}ML Int, {at}Str
> Varchar (19), {at}Cnt TinyInt
> Declare {at}T Table (IDX Int Identity (1, 1), Stng Varchar (4000))
> Select {at}ML = Max (Y.Cnt) From (Select Cnt = Count (*) From Box Group
> By R, C) Y
> Set {at}R = 1
> While {at}R < 10 Begin
> Set {at}Strn = ''
> Set {at}C = 1
> While {at}C < 10 Begin
> Set {at}Cnt = 1
> Set {at}Str = ''
> While {at}Cnt < 10 Begin
> If Exists (Select * From Box Where R = {at}R And C = {at}C And V = {at}Cnt)
> Set {at}Str = {at}Str + Convert (Varchar, {at}Cnt)
> Set {at}Cnt = {at}Cnt + 1
> End
> Set {at}Strn = {at}Strn + {at}Str + Space ({at}ML - Len ({at}Str))
> Set {at}C = {at}C + 1
> Set {at}Strn = {at}Strn + '|'
> If {at}C in (3, 6) Set {at}Strn = {at}Strn + '|'
> End
> Insert {at}T Values ({at}Strn)
> Set {at}R = {at}R + 1
> End
> Select Stng From {at}T
> End
> go
> Drop Procedure dbo.solveit2
> go
> Create Procedure dbo.solveit2 As
> Begin
> Declare {at}RowsLast Int, {at}RowsKeep Int
> Set {at}RowsKeep = 81
> Set {at}RowsLast = 0
> While {at}RowsLast {at}RowsKeep Begin
> Set {at}RowsKeep = {at}RowsLast
> Delete B From Box B Where Exists (Select * From Box Z Where B.V = Z.V
> And (B.C Z.C Or B.R Z.R) And (B.R = Z.R Or B.C = Z.C
Or B.Box =
> Z.Box) And Not Exists (Select * from Box F Where F.R = Z.R And F.C =
> Z.C And F.V Z.V)) Or Exists (Select * From Box B2 Where B2.R = B.R
> And B2.C = B.C And B2.V B.V And (Not Exists (Select * From Box B3
> Where B2.R = B3.R And B3.C B2.C And B2.V = B3.V) Or Not Exists
> (Select * From Box B3 Where B2.C = B3.C And B3.R B2.R And B2.V =
> B3.V) Or Not Exists (Select * From Box B3 Where B2.Box = B3.Box And
> (B2.R B3.R Or B3.C B2.C) And B2.V = B3.V)))
> Select {at}RowsLast = {at}{at}RowCount
> End
> Exec dbo.spViewAll2
> End
> go
> exec dbo.spSudokuInitBox2 'xxx56x421', 'xxxx9xx86', 'xx2xxx7xx',
> '8xx4xxx1x', 'xx5xxx3xx', 'x1xxx8xx7', 'xx1xxx9xx', '47xx2xxxx',
> '639x41xxx'
> Go
> Exec solveit2
>
--- UseNet To RIME Gateway {at} 3/3/05 9:39:20 AM ---
* Origin: MoonDog BBS, Brooklyn,NY, 718 692-2498, 1:278/230 (1:278/230)SEEN-BY: 633/267 270 5030/786 @PATH: 278/230 10/345 106/1 2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.