TIP: Click on subject to list as thread! ANSI
echo: mens_issues
to: All
from: `ian` drawnai{at}hotmail.Co
date: 2005-02-25 17:37:00
subject: Today`s Sudoku was a good one, (in the times that is.)

I had to add two instances of a new rule to my solver for it.

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
 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
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
 '9 1  2  3',
 ' 8  4 6  ',
 '  3  1   ',
 '   3  15 ',
 '7       9',
 ' 94  8   ',
 '   6  5  ',
 '  9 7  3 ',
 '4  2  8 7'

Select Sum (len(v)) -81 from boxes



--- UseNet To RIME Gateway {at} 2/25/05 5:33:39 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™.