| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: The telegraph does the soduko now too Phil. |
"Ian" wrote in message
news:1112183010.998584.175610{at}l41g2000cwc.googlegroups.com...
> And today's was a good one. It forced me to add two more
> rules to my engine.
>
> Actually writing programmes to solve the puzzle becomes more
> fun than doing it, when they manage to find a puzzle that
> contravenes the rules.
>
> (Of course it's quite possible to generate puzzles that short of
> brute force aren't too easily deterministically solveable.)
That's what really bugging me - I am hoping that it will be possible to
create a set of rules that will be able to solve ALL permutations. Of course
it could also turn out to be a problem of the 'travelling sales man' class
(i.e. NOT deterministically solvable). I had a very usefull textbook on
sorting problems which included the maths for helping to determine which
problems were computable from those that are not. Since my last move there
are still a number of boxes full of books and documents that I have never
unpacked - I'm hoping the book in question is in there somewhere!
All that said I'm impressed with the efforts you have already made - my gut
instincts tell me it should be possible to come up with a set of routines to
achieve universal solutions - but then the first time I looked at the
'travelling salesman problem' I was shocked to find out there were no
universal deterministic solutions - so much for 'gut instinct'!!
I do understand your fascination btw - it was the sheer joy of programming
that got me into IT in the first place (making a decent crust at the same
time came a close second of course!).
Phil
>
> -------------------------------------------------
> Use Test
> Drop Table Boxes
> Go
> Create Table Boxes (R TinyInt, C TinyInt, V Varchar (9) Default
> '123456789',
> Box As (3 * ((R - 1) / 3) + (C - 1) / 3 + 1))
> Go
> Drop Table SQ
> Go
> Create Table SQ (Val Tinyint Identity (1,1))
> Go
> Set NoCount On
> Insert SQ Default Values
> Insert SQ Default Values
> Insert SQ Default Values
> Insert SQ Default Values
> Insert SQ Default Values
> Insert SQ Default Values
> Insert SQ Default Values
> Insert SQ Default Values
> Insert SQ Default Values
> Go
> Drop Procedure spSetValue
> Go
> Create Procedure spSetValue {at}R Int, {at}C Int, {at}V Int As Begin
> Set NoCount On
> Declare {at}Rows Int, {at}RC Int
> Update Boxes Set V = Convert (Varchar(1), {at}V) Where R = {at}R And C = {at}C
> Select {at}Rows = {at}{at}Rowcount, {at}RC = {at}{at}Error
> If {at}Rows = 0 Begin Insert Boxes Values ({at}R, {at}C, Convert (Varchar(1),
> {at}V))
> End
> End
> Go
> Drop Procedure spViewAll
> Go
> Create Procedure spViewAll
> As
> Begin
> Set Nocount On
> Declare {at}MaxLen Int, {at}Spacer VarChar(9)
> Select {at}MaxLen = Max(Len(V)) From Boxes Set {at}Spacer = Replace (Space
> ({at}MaxLen), ' ', '-')
>
> Create Table #Box ( A Int Identity (1,1), B Varchar (160) Default
> Space(0)
> )
> Declare {at}C TinyInt, {at}R TinyInt, {at}V Varchar(9), {at}V2 Varchar(160), {at}Rows
> Int,
> {at}RC Int
> Set {at}C = 1
> Set {at}R = 1
> Insert #Box (B) Values ('----------' + {at}Spacer + {at}Spacer + {at}Spacer +
> {at}Spacer + {at}Spacer + {at}Spacer + {at}Spacer + {at}Spacer + {at}Spacer)
> While {at}R <= 9 Begin
> Set {at}V2 = '|'
> While {at}C <= 9 Begin
> Select {at}V = V From Boxes Where C = {at}C And R = {at}R
> if len ({at}V) 1 set {at}v = ''
> Set {at}V2 = {at}V2 + {at}V
> Set {at}V2 = {at}V2 + space ({at}Maxlen - Len({at}v)) + '|'
> Set {at}C = {at}C + 1
> End
> Insert #Box (B) Values ({at}V2)
> If {at}R In (3, 6, 9) Insert #Box (B) Values ('----------' + {at}Spacer +
> {at}Spacer
> + {at}Spacer + {at}Spacer + {at}Spacer + {at}Spacer + {at}Spacer + {at}Spacer + {at}Spacer)
> Set {at}C = 1
> Set {at}R = {at}R + 1
> End
> Select B From #Box Order By A
> Drop Table #Box
> Select V1.R, V2.C, V2.R, V2.C From Boxes V1 Inner Join Boxes V2 On
> V1.V =
> V2.V And (V1.R = V2.R Or V1.C = V2.C Or V1.Box = V2.Box) Where ( V1.R
>
> V2.R Or V2.C V2.C) And Len (V1.V) = 1 And Len (V2.V) = 1
> End
> Go
> Drop Procedure spSudokuInitRow
> Go
> Create Procedure spSudokuInitRow {at}Row TinyInt, {at}Data Char (9) As Begin
> Declare {at}Col TinyInt, {at}Ch Char (1), {at}V TinyInt
> Set {at}Col = 1
> While {at}Col <= 9 Begin
> Set {at}Ch = Substring ({at}Data, {at}Col, 1)
> If {at}Ch in ('1', '2', '3', '4', '5', '6', '7', '8', '9') Begin
> Set {at}V = Convert (TinyInt, {at}Ch)
> Exec spSetValue {at}Row, {at}Col, {at}V
> End
> Set {at}Col = {at}Col + 1
> End
> End
> Go
> Drop Procedure spSudokuInitBox
> Go
> Create Procedure spSudokuInitBox {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 Boxes
> Insert Boxes (R, C) Select R = L.Val, C = C.Val From SQ L, SQ C Where
> Not
> Exists ( Select * From Boxes B Where B.R = L.Val And B.C = C.Val )
> Exec spSudokuInitRow 1, {at}Row1
> Exec spSudokuInitRow 2, {at}Row2
> Exec spSudokuInitRow 3, {at}Row3
> Exec spSudokuInitRow 4, {at}Row4
> Exec spSudokuInitRow 5, {at}Row5
> Exec spSudokuInitRow 6, {at}Row6
> Exec spSudokuInitRow 7, {at}Row7
> Exec spSudokuInitRow 8, {at}Row8
> Exec spSudokuInitRow 9, {at}Row9
> Exec spHaveAGo
> Exec spViewAll
> End
> Go
> Go
> Drop Procedure spEasyRemoval
> Go
> Create Procedure spEasyRemoval
> As
> Begin
> Set NoCount On
> Update B Set B.V = Replace (B.V, T.V, Space(0)) From Boxes B Inner
> Join (
> Select Distinct U.R, U.C, S.V From Boxes U Inner Join Boxes S On (U.Box
> =
> S.Box) Or (U.Box S.Box And U.R = S.R And ((U.R + 2) / 3) = ((S.R +
> 2) /
> 3)) Or (U.Box S.Box And U.C = S.C And ((U.C + 2) / 3) = ((S.C + 2) /
> 3))
> Where CharIndex (S.V, U.V) > 0 And Len (S.V) = 1 And Len (U.V) 1 ) T
> On
> T.R = B.R And T.C = B.C
> If {at}{at}Rowcount = 0
> Begin
> Update B Set B.V = Z.Val From Boxes B Inner Join ( Select R, C, Val
> From
> Boxes U Inner Join ( Select Box, Val From Boxes Inner Join SQ On
> Charindex
> (Convert (Varchar(1), SQ.Val), V) > 0 Where Len (V) 1 Group By Box,
> Val
> Having Count (*) = 1 ) F On U.Box = F.Box Where Charindex
> (Convert(Varchar
> (1), F.Val), U.V) > 0 And Len (U.V) 1 ) Z On Z.R = B.R And Z.C = B.C
>
> If {at}{at}Rowcount = 0
> Begin
> Update B Set B.V = Z.Val From Boxes B Inner Join ( Select U.R, U.C,
> Val
>>From Boxes U Inner Join ( Select C, Val From Boxes Inner Join SQ On
> Charindex (Convert (Varchar(1), SQ.Val), V) > 0 Where Len (V) 1
> Group By
> C, Val Having Count (*) = 1 ) F On U.C = F.C Where Len (U.V) 1 And
> Charindex (Convert(Varchar (1), F.Val), U.V) > 0 ) Z On Z.R = B.R And
> Z.C =
> B.C
> If {at}{at}Rowcount = 0
> Begin
> Update B Set B.V = Z.Val From Boxes B Inner Join ( Select U.R, U.C,
> Val
>>From Boxes U Inner Join ( Select R, Val From Boxes Inner Join SQ On
> Charindex (Convert (Varchar(1), SQ.Val), V) > 0 Where Len (V) 1
> Group By
> R, Val Having Count (*) = 1 ) F On U.R = F.R Where Len (U.V) 1 And
> Charindex (Convert(Varchar (1), F.Val), U.V) > 0 ) Z On Z.R = B.R And
> Z.C =
> B.C
> If {at}{at}Rowcount = 0
> Begin
> Update B Set B.V = Replace (B.V, X.V, Space(0)) From Boxes B Inner Join
> (
> Select Distinct O.Box, O.C, Z.V From Boxes O Inner Join ( Select
> Distinct
> T.Box, T.C, V = SubString (T.V, S.Val, 1) From ( Select Distinct B2.V,
> B2.C,
> B2.Box, Val = (Select Sum (Len (BB.V)) From Boxes BB Where BB.C = B2.C
> And
> BB.Box B2.Box) From Boxes B2 ) T Cross Join SQ S Where T.Val = 6 And
> Len
> (SubString (T.V, S.Val, 1)) = 1 ) Z On Z.Box = O.Box And Z.C O.C ) X
> On
> X.Box = B.Box And X.C = B.C Where CharIndex (X.V, B.V) 0 And Len
> (B.V)
> 1
> If {at}{at}Rowcount = 0
> Begin
> Update B Set B.V = Replace (B.V, X.V, Space(0)) From Boxes B Inner Join
> (
> Select Distinct O.Box, O.R, Z.V From Boxes O Inner Join ( Select
> Distinct
> T.Box, T.R, V = SubString (T.V, S.Val, 1) From ( Select Distinct B2.V,
> B2.R,
> B2.Box, Val = (Select Sum (Len (BB.V)) From Boxes BB Where BB.R = B2.R
> And
> BB.Box B2.Box) From Boxes B2 ) T Cross Join SQ S Where T.Val = 6 And
> Len
> (SubString (T.V, S.Val, 1)) = 1 ) Z On Z.Box = O.Box And Z.R O.R ) X
> On
> X.Box = B.Box And X.R = B.R Where CharIndex (X.V, B.V) 0 And Len
> (B.V)
> 1
> If {at}{at}Rowcount = 0
> Begin
> Update D Set D.V = Replace (D.V, P.Ch, Space(0)) From Boxes D Inner
> Join (
> Select T.* From (Select B.Box, B.C, Ch = Substring (B.V, S.Val, 1) From
> Boxes B Inner Join SQ S On Substring (B.V, S.Val, 1) 0 Where Len
> (B.V) > 1
> ) T Left Join (Select B.Box, B.C, Ch = Substring (B.V, S.Val, 1) From
> Boxes B
> Inner Join SQ S On Substring (B.V, S.Val, 1) 0 Where Len (B.V) > 1)
> U On
> T.Box = U.Box And T.C U.C And T.Ch = U.Ch Where U.Box Is Null) P On
> P.C
> = D.C And P.Box D.Box And Charindex (P.Ch, D.V) > 0 And
Len (D.V) >
> 1
> If {at}{at}Rowcount = 0
> Begin
> Update D Set D.V = Replace (D.V, P.Ch, Space(0)) From Boxes D Inner
> Join (
> Select T.* From (Select B.Box, B.R, Ch = Substring (B.V, S.Val, 1) From
>
> Boxes B Inner Join SQ S On Substring (B.V, S.Val, 1) 0 Where Len
> (B.V) > 1
> ) T Left Join (Select B.Box, B.R, Ch = Substring (B.V, S.Val, 1) From
> Boxes B
> Inner Join SQ S On Substring (B.V, S.Val, 1) 0 Where Len (B.V) > 1)
> U On
> T.Box = U.Box And T.R U.R And T.Ch = U.Ch Where U.Box Is Null) P On
> P.R =
> D.R And P.Box D.Box And Charindex (P.Ch, D.V) > 0 And Len
(D.V) > 1
> End
> End
> End
> End
> End
> End
> End
> End
> Go
> Drop Procedure spHaveAGo
> Go
> Create Procedure spHaveAGo
> As
> Begin
> Set NoCount On
> Declare {at}NumberLeft Int, {at}RastCount Int
> Select {at}NumberLeft = Sum (len (v)) - 81 From Boxes
> Set {at}RastCount = 5000000
> While {at}NumberLeft < {at}RastCount Begin
> Set {at}RastCount = {at}NumberLeft
> Exec spEasyRemoval
> Select {at}NumberLeft = Sum (len (v)) - 81 From Boxes
> End
> If Exists ( Select * From Boxes V1 Inner Join Boxes V2 On V1.V = V2.V
> And
> (V1.R = V2.R Or V1.C = V2.C Or V1.Box = V2.Box) Where (V1.R V2.R Or
> V2.C
> V2.C) And Len (V1.V) = 1 And Len (V2.V) = 1 ) Print 'Error
> Diagnosing'
>
> End
> Go
> set nocount on
> exec spSudokuInitBox
> 'xx16x7xxx',
> 'x3xxxx98x',
> '45xxx17xx',
> '3x27xxx4x',
> 'xxxx5xxxx',
> 'x6xxx38x7',
> 'xx82xxx19',
> 'x94xxxx7x',
> 'xxx9x85xx'
>
> Select Sum (len(v)) -81 from boxes
>
--- UseNet To RIME Gateway {at} 3/30/05 8:47:55 PM ---
* 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™.