Skip to comments.
Sudoku math puzzle / proof (vanity)
None ^
| Aug 29, 2006
| self
Posted on 08/29/2006 9:17:38 AM PDT by taxcontrol
Folks, I'm stumped... I need help with the following:
Given - Two completed suduko puzzles A (correct answer) and R (unknown result).
Question: What is the fewest number of checks that can be made to prove that A = R for the following assumptions:
Assumption1 Assume that in R, no sub area has any duplicate numbers (ie, 1-9 inclusive)
Assumption2 Assume that in R, no row has any duplicate numbers (can also be proven using columns instead of rows.
Also - prove true or false When A = R, the diagonals will always include at least 1 duplicate number
Write a proof for each.
TOPICS:
KEYWORDS: generalchat; homeworkhelp; math; proof; sudoku; wob
Navigation: use the links below to view more comments.
first 1-20, 21-40, 41-60, 61-80 ... 101-105 next last
Extra credit math work that just has me stummped and I'm not too proud to admit I need HELP!!! Heck, I cant even conceptualize where to begin.
To: taxcontrol
Why isn't this in breaking news?
2
posted on
08/29/2006 9:19:23 AM PDT
by
frogjerk
(REUTERS: We give smoke and mirrors a bad name)
To: frogjerk
3
posted on
08/29/2006 9:21:41 AM PDT
by
SunTzuWu
(Hans Delbruck - Scientist and Saint.)
To: frogjerk
LOL - simply put.... it's not breaking news... it's breaking me. It's breaking my brain to pieces, keeping me up at night, etc.
To: taxcontrol
To: taxcontrol
6
posted on
08/29/2006 9:23:31 AM PDT
by
Toskrin
(It didn't seem nostalgic when I was doing it)
To: taxcontrol
I thought you were talking about Santoku!:)
7
posted on
08/29/2006 9:24:55 AM PDT
by
restornu
(Steadfast as we move into troublesome days ahead: We do not take counsel from our fears.)
To: taxcontrol
And now for something considerably easier:
If you were to put a coin into an empty bottle and then insert a cork in the bottle's opening, how could you remove the coin without taking out the cork or breaking the bottle?
8
posted on
08/29/2006 9:24:58 AM PDT
by
Quilla
To: taxcontrol
9
posted on
08/29/2006 9:27:15 AM PDT
by
restornu
(Steadfast as we move into troublesome days ahead: We do not take counsel from our fears.)
To: Quilla
To: taxcontrol
Close enough ;-)
PROGRAM
typComboQ QUEUE,TYPE
Cells BYTE,DIM(9)
UsedFlag BYTE
END
MAP
InitGrid
PrintGrid(LONG pPasses)
CheckRow(BYTE pR,BYTE pC,BYTE pD),BYTE
CheckCol(BYTE pR,BYTE pC,BYTE pD),BYTE
CheckCube(BYTE pR,BYTE pC,BYTE pD),BYTE
CheckDone,BYTE
RemString(BYTE pX),STRING
FillGrid,LONG
ISINROW(STRING pS),BYTE
ISINCOL(STRING pS),BYTE
CubeCellTOGrid(BYTE pCube,BYTE pCell),byte
CubeCellTORow(BYTE pCube,BYTE pCell),byte
CubeCellTOCol(BYTE pCube,BYTE pCell),byte
RowColToCube(BYTE pR,BYTE pC),byte
RowColToGrid(BYTE pR,BYTE pC),Byte
LoadComboQ(*typComboQ ComboQ, BYTE R, BYTE C, BYTE Cube)
PickDigitCol(*typComboQ ComboQ, BYTE R,BYTE C)
PickDigitRow(*typComboQ ComboQ, BYTE R,BYTE C)
PickDigitCube(*typComboQ ComboQ, BYTE Cube,BYTE Cell)
TestCell(*typComboQ ComboQ, BYTE C),BYTE
DeleteUnused(*typComboQ ComboQ),LONG
ClearUsedFlags(*typComboQ ComboQ)
TESTGridRow(BYTE R,*typComboQ CQ),LONG
TESTGridCol(BYTE R,*typComboQ CQ),LONG
TESTGridCube(BYTE R,*typComboQ CQ),LONG
CheckCombinations(*typComboQ CQ1,*typComboQ CQ2,*typComboQ CQ3)
CheckCombinations(*typComboQ CQ1,*typComboQ CQ2,*typComboQ CQ3,*typComboQ CQ4,*typComboQ CQ5,*typComboQ CQ6)
END!MAP
!! This default group was give to me by Ubi
!! and is reported to be the toughest on record
!! to Solve.
GivenGroup GROUP,PRE(GG)
Line1 STRING('7 8 3 ')
Line2 STRING(' 2 1 ')
Line3 STRING('5 ')
Line4 STRING(' 4 26')
Line5 STRING('3 8 ')
Line6 STRING(' 1 9 ')
Line7 STRING(' 9 6 4')
Line8 STRING(' 7 5 ')
Line9 STRING(' ')
END!GROUP
!GivenGroup GROUP,PRE(GG)
!Line1 string(' 6 4 9 ')
!Line2 STRING('547 6 3')
!Line3 STRING(' 8 ')
!Line4 STRING(' 293 4 ')
!Line5 STRING(' 2 ')
!Line6 STRING(' 5 678 ')
!Line7 STRING(' 1 ')
!Line8 STRING('6 8 175')
!Line9 STRING(' 5 7 3 ')
! END!GROUP
Given STRING(1),DIM(81),OVER(GivenGroup)
Grid GROUP,DIM(81)
Digit BYTE
Digits BYTE,DIM(9)
END!GROUP
StFEQ LONG
Progress1 LONG
ProgressFEQ LONG
CODE
InitGrid
PrintGrid(FillGrid())
!==============================================================================
InitGrid PROCEDURE
X BYTE,AUTO
Y BYTE,AUTO
Window WINDOW('Starting Grid'),AT(,,110,132),FONT('Courier',8,,),CENTER,TIMER(1),SYSTEM,GRAY,DOUBLE
ENTRY(@s20),AT(2,6,65,10),USE(GG:Line1),FONT('Courier',,,)
ENTRY(@s20),AT(2,18,65,10),USE(GG:Line2)
BUTTON('Easy 12'),AT(70,20,34,14),USE(?P1)
ENTRY(@s20),AT(2,29,65,10),USE(GG:Line3)
BUTTON('Evil 10'),AT(70,80,34,14),USE(?P2)
ENTRY(@s20),AT(2,40,65,10),USE(GG:Line4)
ENTRY(@s20),AT(2,51,65,10),USE(GG:Line5)
BUTTON('Evil 13'),AT(70,95,34,14),USE(?P3)
ENTRY(@s20),AT(2,62,65,10),USE(GG:Line6)
BUTTON('Hard 18'),AT(70,35,34,14),USE(?P4)
ENTRY(@s20),AT(2,73,65,10),USE(GG:Line7)
ENTRY(@s20),AT(2,85,65,10),USE(GG:Line8)
BUTTON('Hard 19'),AT(70,50,34,14),USE(?P5)
ENTRY(@s20),AT(2,96,65,10),USE(GG:Line9)
BUTTON('Easy 10'),AT(70,5,34,14),USE(?P6)
BUTTON('Go'),AT(1,109,45,14),USE(?GO_Btn)
PROMPT('Default Grid is the hardest'),AT(47,111,61,19),USE(?Prompt1)
BUTTON('Evil 20'),AT(70,65,34,14),USE(?P7)
END
CODE
OPEN(Window)
Accept
CASE Accepted()
OF ?GO_Btn
Post(Event:CloseWindow)
OF ?P1
GG:Line1 =' '
GG:Line2 ='8 17 54 6'
GG:Line3 =' 9 6 3 8 '
GG:Line4 ='3 2 8 4'
GG:Line5 =' 2 1 3 '
GG:Line6 ='4 9 6 1'
GG:Line7 =' 8 1 7 4 '
GG:Line8 ='6 58 92 7'
GG:Line9 =' '
GG:Line1 ='8 7 1 2'
GG:Line2 =' 6 7 '
GG:Line3 =' 17 89 '
GG:Line4 =' 173 '
GG:Line5 ='7 6'
GG:Line6 =' 956 '
GG:Line7 =' 95 41 '
GG:Line8 =' 8 5 '
GG:Line9 ='3 6 5 7'
DISPLAY()
OF ?P2
GG:Line1 =' 35 1'
GG:Line2 =' 396 '
GG:Line3 ='869 3 '
GG:Line4 =' 72 1 6 '
GG:Line5 =' 742 '
GG:Line6 =' 9 6 17 '
GG:Line7 =' 7 243'
GG:Line8 =' 134 '
GG:Line9 ='6 79 '
GG:Line1 =' 3 '
GG:Line2 =' 28 69'
GG:Line3 =' 9 1 '
GG:Line4 =' 92 78'
GG:Line5 =' 7 1 '
GG:Line6 ='86 54 '
GG:Line7 =' 8 2 '
GG:Line8 ='12 56 '
GG:Line9 =' 4 '
DISPLAY()
OF ?P3
GG:Line1 =' 16 7 '
GG:Line2 ='2 7 34 '
GG:Line3 ='8 '
GG:Line4 =' 35 9'
GG:Line5 ='4 5 1 7'
GG:Line6 ='6 72 '
GG:Line7 =' 2'
GG:Line8 =' 81 5 6'
GG:Line9 =' 2 87 '
GG:Line1 ='95 67 '
GG:Line2 =' 731 '
GG:Line3 ='8 561 '
GG:Line4 ='23 '
GG:Line5 =' 9 1 '
GG:Line6 =' 37'
GG:Line7 =' 145 9'
GG:Line8 =' 942 '
GG:Line9 =' 85 21'
DISPLAY()
OF ?P4
GG:Line1 =' 3 '
GG:Line2 ='1 4238 '
GG:Line3 ='8 5 9'
GG:Line4 ='68 9 '
GG:Line5 =' 567 '
GG:Line6 =' 8 43'
GG:Line7 ='9 3 7'
GG:Line8 =' 1854 6'
GG:Line9 =' 1 '
DISPLAY()
OF ?P5
GG:Line1 ='83 9 1 7'
GG:Line2 =' 2 7 8 '
GG:Line3 =' 1 '
GG:Line4 ='2 96 '
GG:Line5 =' 4 8 '
GG:Line6 =' 57 8'
GG:Line7 =' 1 '
GG:Line8 =' 3 6 9 '
GG:Line9 ='9 2 7 54'
DISPLAY()
OF ?P6
GG:Line1 =' 8 4'
GG:Line2 =' 6 24 '
GG:Line3 ='3 8 9'
GG:Line4 =' 3 1 5 '
GG:Line5 =' 53 84 '
GG:Line6 =' 1 7 8 '
GG:Line7 ='7 1 6'
GG:Line8 =' 94 3 '
GG:Line9 ='5 6 '
DISPLAY()
OF ?P7
GG:Line1 =' 2 9'
GG:Line2 ='48 5 '
GG:Line3 =' 31 47 '
GG:Line4 =' 5 8 '
GG:Line5 ='2 5 1 6'
GG:Line6 =' 1 3 '
GG:Line7 =' 29 64 '
GG:Line8 =' 3 61'
GG:Line9 ='6 9 '
DISPLAY()
END
END
CLEAR(Grid)
LOOP X = 1 TO 81
IF Given[X]
Grid[X].Digit = Given[X]
ELSE
LOOP Y = 1 TO 9
Grid[X].Digits[Y] = Y
END!LOOP
END!IF
END!LOOP
CLOSE(Window)
!==============================================================================
PrintGrid PROCEDURE(LONG pPasses)
R BYTE,AUTO
B BYTE,AUTO
C BYTE,AUTO
X BYTE,AUTO
S CSTRING(500)
CODE
LOOP R = 1 TO 9
LOOP B = 1 TO 3
LOOP C = 1 TO 3
X = (R-1)*9 + (B-1)*3 + C
S = S & Grid[X].Digit & CHOOSE(C<3, ' ', '')
END!LOOP
IF B < 3
S = S &' '
END!IF
END!LOOP
S = S &'|'& CHOOSE((R+1)%3, '|', '')
END!LOOP
MESSAGE(S &'|'& pPasses &' passes to solve|', 'Solution')
!==============================================================================
CheckRow PROCEDURE(BYTE pR,BYTE pC,BYTE pD) !,BYTE
R BYTE,AUTO
C BYTE,AUTO
CODE
R = (pR-1)*9
LOOP C = 1 TO 9
IF C <> pC |
AND Grid[R+C].Digit = pD
RETURN C
END!IF
END!LOOP
RETURN 0
!==============================================================================
CheckCol PROCEDURE(BYTE pR,BYTE pC,BYTE pD) !,BYTE
R BYTE,AUTO
CODE
LOOP R = 1 TO 9
IF R <> pR |
AND Grid[(R-1)*9+pC].Digit = pD
RETURN R
END!IF
END!LOOP
RETURN 0
!==============================================================================
CheckCube PROCEDURE(BYTE pR,BYTE pC,BYTE pD) !,BYTE
RS BYTE,AUTO
RE BYTE,AUTO
CS BYTE,AUTO
CE BYTE,AUTO
R BYTE,AUTO
C BYTE,AUTO
X BYTE,AUTO
CODE
CASE pR
OF 1 TO 3; RS = 1; RE = 3
OF 4 TO 6; RS = 4; RE = 6
OF 7 TO 9; RS = 7; RE = 9
END!CASE
CASE pC
OF 1 TO 3; CS = 1; CE = 3
OF 4 TO 6; CS = 4; CE = 6
OF 7 TO 9; CS = 7; CE = 9
END!CASE
LOOP R = RS TO RE
LOOP C = CS TO CE
X = (R-1)*9 + C
IF (R <> pR OR C <> pC) |
AND Grid[X].Digit = pD
RETURN X
END!IF
END!LOOP
END!LOOP
RETURN 0
!==============================================================================
CheckDone PROCEDURE !,BYTE
X BYTE,AUTO
Z BYTE(0)
CODE
LOOP X = 1 TO 81
IF ~Grid[X].Digit
Z += 1
END!IF
END!LOOP
RETURN Z
! Return all Digits still posible for a given
! Grid Number
RemString PROCEDURE(BYTE pX)!,string
S String(9)
C BYTE
CODE
S = ''
LOOP C = 1 TO 9
IF Grid[pX].Digits[C]
S = CLIP(S)&C
END
END
RETURN (S)
! Returns True if all cell numbers
! are in the same row
ISINROW PROCEDURE(STRING pS)!,BYTE
R BYTE
X BYTE
C BYTE
CODE
C=(0+pS[1])
R = 1+INT((C-1)/3)
LOOP X = 1 TO LEN(CLIP(pS))
C=(0+pS[X])
IF R<>(1+INT((C-1)/3))
R=0
BREAK
END
END
RETURN (R)
! Returns True if all cell numbers
! are in the same column
ISINCOL PROCEDURE(STRING pS)!,BYTE
R BYTE
X BYTE
C BYTE
CODE
C=pS[1]
R = ((C-1)%3)+1
LOOP X = 1 TO LEN(CLIP(pS))
C=pS[X]
IF R<>((C-1)%3)+1
R=0
BREAK
END
END
RETURN (R)
!_________________________________________________________________________________
!_________________________________________________________________________________
! This is a set up routine that calls the recursive functions that build
! a queue of all posible combinations still valid for a row, column, or
! cube.
!_________________________________________________________________________________
LoadComboQ PROCEDURE(*typComboQ ComboQ, BYTE R, BYTE C, BYTE Cube)
X BYTE
CODE
FREE(ComboQ)
LOOP X = 1 TO 9
ComboQ.Cells[X]= 0
END
ComboQ.UsedFlag = False
IF R THEN PickDigitRow(ComboQ, R,1).
IF C THEN PickDigitCol(ComboQ, 1,C).
IF Cube THEN PickDigitCube(ComboQ, Cube,1).
RETURN
!_________________________________________________________________________________
! Builds all posible combinations still valid for a Cube
!_________________________________________________________________________________
PickDigitCube PROCEDURE(*typComboQ ComboQ, BYTE Cube,BYTE Cell)!,BYTE
D BYTE
X BYTE
CODE
IF Cell>9
ADD(ComboQ)
RETURN
END
X = CubeCellToGrid(Cube,Cell)
IF Grid[X].Digit
ComboQ.Cells[Cell] = Grid[X].Digit
IF TestCell(ComboQ, Cell)
PickDigitCube(ComboQ, Cube,Cell+1)
END
ELSE
LOOP D = 1 TO 9
IF Grid[X].Digits[D]
ComboQ.Cells[Cell]= D
IF TestCell(ComboQ, Cell)
PickDigitCube(ComboQ, Cube,Cell+1)
END
END
END
END
RETURN
!_________________________________________________________________________________
! Builds all posible combinations still valid for a Column
!_________________________________________________________________________________
PickDigitCol PROCEDURE(*typComboQ ComboQ, BYTE R,BYTE C)!,BYTE
D BYTE
X BYTE
CODE
IF R>9
ADD(ComboQ)
RETURN
END
X = (R-1)*9 + C
IF Grid[X].Digit
ComboQ.Cells[R]= Grid[X].Digit
IF TestCell(ComboQ, R)
PickDigitCol(ComboQ, R+1,C)
END
ELSE
LOOP D = 1 TO 9
IF Grid[X].Digits[D]
ComboQ.Cells[R]= D
IF TestCell(ComboQ, R)
PickDigitCol(ComboQ, R+1,C)
END
END
END
END
RETURN
!_________________________________________________________________________________
! Builds all posible combinations still valid for a row
!_________________________________________________________________________________
PickDigitRow PROCEDURE(*typComboQ ComboQ, BYTE R,BYTE C)!,BYTE
D BYTE
X BYTE
CODE
IF C>9
ADD(ComboQ)
RETURN
END
X = (R-1)*9 + C
IF Grid[X].Digit
ComboQ.Cells[C]= Grid[X].Digit
IF TestCell(ComboQ, C)
PickDigitRow(ComboQ, R,C+1)
END
ELSE
LOOP D = 1 TO 9
IF Grid[X].Digits[D]
ComboQ.Cells[C]= D
IF TestCell(ComboQ,C)
PickDigitRow(ComboQ,R,C+1)
END
END
END
END
RETURN
!_________________________________________________________________________________
! Returns False if the value in byte # C has already been filled into
! one of the prior buckets.
!_________________________________________________________________________________
TestCell PROCEDURE(*typComboQ ComboQ, BYTE C)!,BYTE
ThisC BYTE
X BYTE
CODE
ThisC = ComboQ.Cells[C]
IF C>1
LOOP X = 1 TO C-1
IF ComboQ.Cells[X] = ThisC
ThisC = 0
BREAK
END
END
END
RETURN (ThisC)
!_________________________________________________________________________________
! Delete any rows in the Queue where UsedFlag=0
!_________________________________________________________________________________
DeleteUnused PROCEDURE(*typComboQ ComboQ)!,LONG
Dcnt LONG
CODE
Dcnt=0
GET(ComboQ,1)
LOOP
IF ~ComboQ.UsedFlag
DELETE(ComboQ)
Dcnt+=1
GET(ComboQ,1)
IF ERRORCODE() THEN BREAK.
CYCLE
END
GET(ComboQ,POINTER(ComboQ)+1)
IF ERRORCODE() THEN BREAK.
END
RETURN (Dcnt)
!_________________________________________________________________________________
!_________________________________________________________________________________
! Check all combinations for rows 1 2 & 3, 4 5 & 6, and 7 8 & 9
!_________________________________________________________________________________
CheckCombinations PROCEDURE(*typComboQ CQ1,*typComboQ CQ2,*typComboQ CQ3)
C1 LONG
C2 LONG
RowOK BYTE
TotalToDo ULONG
TotalDone ULONG
CODE
GET(CQ1,1)
LOOP
GET(CQ2,1)
LOOP
RowOK=True
Progress1 = 100*(POINTER(CQ1)*RECORDS(CQ2)+POINTER(CQ2))/(RECORDS(CQ1)*RECORDS(CQ2))
DISPLAY(ProgressFEQ)
LOOP C2 = 1 TO 9
LOOP C1=(1+3*INT((C2-1)/3)) TO (3+3*INT((C2-1)/3))
IF CQ1.Cells[C1]=CQ2.Cells[C2]
RowOK=False
BREAK
END
END
IF ~RowOK THEN BREAK.
END ! LOOP C2
IF RowOK
GET(CQ3,1)
LOOP
RowOK=True
LOOP C2 = 1 TO 9
LOOP C1=(1+3*INT((C2-1)/3)) TO (3+3*INT((C2-1)/3))
IF CQ1.Cells[C1]=CQ3.Cells[C2] OR CQ2.Cells[C1]=CQ3.Cells[C2]
RowOK=False
BREAK
END
END
IF ~RowOK THEN BREAK.
END ! LOOP C2
IF RowOK
CQ1.UsedFlag = True
CQ2.UsedFlag = True
CQ3.UsedFlag = True
PUT(CQ1)
PUT(CQ2)
PUT(CQ3)
END
GET(CQ3,pointer(CQ3)+1)
IF ERRORCODE() THEN BREAK.
END ! LOOP Each CQ2
END ! IF Row 2 OK
GET(CQ2,pointer(CQ2)+1)
IF ERRORCODE() THEN BREAK.
END! LOOP Each CQ2
GET(CQ1,POINTER(CQ1)+1)
IF ERRORCODE() THEN BREAK.
END ! loop each CQ1
!_________________________________________________________________________________
!_________________________________________________________________________________
! Check all combinations for rows 1 2 3 4 5 & 6, 1 2 3 7 8 & 9, and 4 5 6 7 8 & 9
!_________________________________________________________________________________
CheckCombinations PROCEDURE(*typComboQ CQ1,*typComboQ CQ2,*typComboQ CQ3,*typComboQ CQ4,*typComboQ CQ5,*typComboQ CQ6)
C1 LONG
C2 LONG
C3 LONG
RowOK BYTE
CODE
GET(CQ1,1)
LOOP
GET(CQ2,1)
LOOP
RowOK=True
Progress1 = 100*(POINTER(CQ1)*RECORDS(CQ2)+POINTER(CQ2))/(RECORDS(CQ1)*RECORDS(CQ2))
DISPLAY(ProgressFEQ)
LOOP C2 = 1 TO 9
LOOP C1=(1+3*INT((C2-1)/3)) TO (3+3*INT((C2-1)/3))
IF CQ1.Cells[C1]=CQ2.Cells[C2]
RowOK=False
BREAK
END
END
IF ~RowOK THEN BREAK.
END ! LOOP C2
IF RowOK
GET(CQ3,1)
LOOP
RowOK=True
LOOP C2 = 1 TO 9
LOOP C1=(1+3*INT((C2-1)/3)) TO (3+3*INT((C2-1)/3))
IF CQ1.Cells[C1]=CQ3.Cells[C2] OR CQ2.Cells[C1]=CQ3.Cells[C2]
RowOK=False
BREAK
END
END
IF ~RowOK THEN BREAK.
END ! LOOP C2
IF RowOK
GET(CQ4,1)
LOOP
RowOK=True
LOOP C1 = 1 TO 9
IF CQ1.Cells[C1]=CQ4.Cells[C1] OR CQ2.Cells[C1]=CQ4.Cells[C1] OR CQ3.Cells[C1]=CQ4.Cells[C1]
RowOK=False
BREAK
END
IF ~RowOK THEN BREAK.
END ! LOOP C2
IF RowOK
GET(CQ5,1)
LOOP
RowOK = True
LOOP C1 = 1 TO 9
IF CQ1.Cells[C1]=CQ5.Cells[C1] OR CQ2.Cells[C1]=CQ5.Cells[C1] OR CQ3.Cells[C1]=CQ5.Cells[C1]
RowOK=False
BREAK
END
IF ~RowOK THEN BREAK.
LOOP C2=(1+3*INT((C1-1)/3)) TO (3+3*INT((C1-1)/3))
IF CQ4.Cells[C1]=CQ5.Cells[C2]
RowOK=False
BREAK
END
END
IF ~RowOK THEN BREAK.
END ! LOOP C1
IF RowOK
GET(CQ6,1)
LOOP
RowOK=True
LOOP C2 = 1 TO 9
IF CQ1.Cells[C2]=CQ6.Cells[C2] OR CQ2.Cells[C2]=CQ6.Cells[C2] OR CQ3.Cells[C2]=CQ6.Cells[C2]
RowOK=False
BREAK
END
IF ~RowOK THEN BREAK.
LOOP C1=(1+3*INT((C2-1)/3)) TO (3+3*INT((C2-1)/3))
IF CQ4.Cells[C1]=CQ6.Cells[C2] OR CQ5.Cells[C1]=CQ6.Cells[C2]
RowOK=False
BREAK
END
END
IF ~RowOK THEN BREAK.
END ! LOOP C2
IF RowOK
CQ1.UsedFlag = True
CQ2.UsedFlag = True
CQ3.UsedFlag = True
CQ4.UsedFlag = True
CQ5.UsedFlag = True
CQ6.UsedFlag = True
PUT(CQ1)
PUT(CQ2)
PUT(CQ3)
PUT(CQ4)
PUT(CQ5)
PUT(CQ6)
END !RowOK for CQ6
GET(CQ6,pointer(CQ6)+1)
IF Errorcode() THEN BREAK.
END ! CQ6 Loop
END !RowOK for CQ5
GET(CQ5,pointer(CQ5)+1)
IF Errorcode() THEN BREAK.
END ! CQ5 Loop
END! RowOK for CQ4
GET(CQ4,pointer(CQ4)+1)
IF Errorcode() THEN BREAK.
END ! CQ4 LOOP
END ! RowOK for CQ3
GET(CQ3,pointer(CQ3)+1)
IF ERRORCODE() THEN BREAK.
END ! LOOP Each CQ2
END ! IF Row 2 OK
GET(CQ2,pointer(CQ2)+1)
IF ERRORCODE() THEN BREAK.
END! LOOP Each CQ2
GET(CQ1,POINTER(CQ1)+1)
IF ERRORCODE() THEN BREAK.
END ! loop each CQ1
TESTGridRow PROCEDURE(BYTE R,*typComboQ CQ)
X LONG
TestGrid GROUP,DIM(9)
Digits BYTE,DIM(9)
END!GROUP
RtVal LONG
C BYTE
D BYTE
CODE
CLEAR(TestGrid)
RtVal = 0
LOOP X = 1 TO RECORDS(CQ)
GET(CQ,X)
LOOP C = 1 TO 9
TestGrid[C].Digits[CQ.Cells[C]] = 1
D = (R-1)*9 + C
IF ~Grid[D].Digit
(StFEQ+D){Prop:Text} = CQ.Cells[C]
DISPLAY((StFEQ+D))
END
END
END
LOOP C = 1 TO 9
X = (R-1)*9 + C
IF ~Grid[X].Digit
LOOP D = 1 TO 9
IF Grid[X].Digits[D] AND ~TestGrid[C].Digits[D]
Grid[X].Digits[D]=0
RtVal += 1
END
END
END
END
RETURN (RtVal)
TESTGridCol PROCEDURE(BYTE C,*typComboQ CQ)
X LONG
TestGrid GROUP,DIM(9)
Digits BYTE,DIM(9)
END!GROUP
RtVal LONG
R BYTE
D BYTE
CODE
CLEAR(TestGrid)
RtVal = 0
LOOP X = 1 TO RECORDS(CQ)
GET(CQ,X)
LOOP R = 1 TO 9
TestGrid[R].Digits[CQ.Cells[R]] = 1
D = (R-1)*9 + C
IF ~Grid[D].Digit
(StFEQ+D){Prop:Text} = CQ.Cells[R]
DISPLAY((StFEQ+D))
END
END
END
LOOP R = 1 TO 9
X = (R-1)*9 + C
IF ~Grid[X].Digit
LOOP D = 1 TO 9
IF Grid[X].Digits[D] AND ~TestGrid[R].Digits[D]
Grid[X].Digits[D]=0
RtVal += 1
END
END
END
END
RETURN (RtVal)
TESTGridCube PROCEDURE(BYTE Cube,*typComboQ CQ)
X LONG
TestGrid GROUP,DIM(9)
Digits BYTE,DIM(9)
END!GROUP
RtVal LONG
Cell BYTE
D BYTE
CODE
CLEAR(TestGrid)
RtVal = 0
LOOP X = 1 TO RECORDS(CQ)
GET(CQ,X)
LOOP Cell = 1 TO 9
TestGrid[Cell].Digits[CQ.Cells[Cell]] = 1
D = CubeCellToGrid(Cube,Cell)
IF ~Grid[D].Digit
(StFEQ+D){Prop:Text} = CQ.Cells[Cell]
DISPLAY((StFEQ+D))
END
END
END
LOOP Cell = 1 TO 9
X = CubeCellToGrid(Cube,Cell)
IF ~Grid[X].Digit
LOOP D = 1 TO 9
IF Grid[X].Digits[D] AND ~TestGrid[Cell].Digits[D]
Grid[X].Digits[D]=0
RtVal += 1
END
END
END
END
RETURN (RtVal)
ClearUsedFlags PROCEDURE(*typComboQ ComboQ)
X LONG
CODE
IF ~RECORDS(ComboQ) THEN RETURN.
LOOP X = 1 TO RECORDS(ComboQ)
GET(ComboQ,X)
ComboQ.UsedFlag=False
PUT(ComboQ)
END
!==============================================================================
FillGrid PROCEDURE !,LONG
R BYTE,AUTO ! Row 1-9
C BYTE,AUTO ! Col 1-9
Cube BYTE,AUTO ! Cube #1-9
Cell BYTE,AUTO ! Cell in Cube 1-9
D BYTE,AUTO ! Digit
X LONG,AUTO
Y BYTE,AUTO
F BYTE,AUTO
Z BYTE(81)
P LONG(0)
ShowAll BYTE
POSDigits BYTE,DIM(9) ! Process of elimination Digits
DidSomething byte
S STRING(9),DIM(9)
ComboQ QUEUE(typComboQ),pre(CQ)
END
Window WINDOW('Solving Sudoku...'),AT(,,147,132),FONT('MS Sans Serif',12,,),CENTER,TIMER(1),SYSTEM,GRAY, |
DOUBLE
STRING('Remaining:'),AT(22,6),USE(?String2)
STRING(@n2),AT(62,6,14,10),USE(Z),RIGHT,FONT(,,,FONT:bold)
BUTTON('Run All Checks'),AT(86,13,52,9),USE(?RunAll),FONT('Arial',10,,FONT:bold)
PANEL,AT(6,22,77,91),USE(?Panel10),BEVEL(-2,-2)
PANEL,AT(8,24,25,30),USE(?Panel11),BEVEL(1,-1)
PANEL,AT(32,24,25,30),USE(?Panel12),BEVEL(1,-1)
PANEL,AT(56,24,25,30),USE(?Panel13),BEVEL(1,-1)
PANEL,AT(8,53,25,29),USE(?Panel21),BEVEL(1,-1)
PANEL,AT(32,53,25,29),USE(?Panel22),BEVEL(1,-1)
PANEL,AT(56,53,25,29),USE(?Panel23),BEVEL(1,-1)
STRING('8'),AT(8,25,8,10),USE(?String11),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(16,25,8,10),USE(?String12),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(24,25,8,10),USE(?String13),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(33,25,8,10),USE(?String14),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(41,25,8,10),USE(?String15),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(49,25,8,10),USE(?String16),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(57,25,8,10),USE(?String17),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(65,25,8,10),USE(?String18),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(73,25,8,10),USE(?String19),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(8,34,8,10),USE(?String21),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(16,34,8,10),USE(?String22),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(24,34,8,10),USE(?String23),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(33,34,8,10),USE(?String24),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(41,34,8,10),USE(?String25),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(49,34,8,10),USE(?String26),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(57,34,8,10),USE(?String27),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(65,34,8,10),USE(?String28),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(73,34,8,10),USE(?String29),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(8,43,8,10),USE(?String31),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(16,43,8,10),USE(?String32),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(24,43,8,10),USE(?String33),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(33,43,8,10),USE(?String34),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(41,43,8,10),USE(?String35),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(49,43,8,10),USE(?String36),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(57,43,8,10),USE(?String37),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(65,43,8,10),USE(?String38),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(73,43,8,10),USE(?String39),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(8,54,8,10),USE(?String41),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(16,54,8,10),USE(?String42),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(24,54,8,10),USE(?String43),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(33,54,8,10),USE(?String44),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(41,54,8,10),USE(?String45),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(49,54,8,10),USE(?String46),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(57,54,8,10),USE(?String47),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(65,54,8,10),USE(?String48),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(73,54,8,10),USE(?String49),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(8,63,8,10),USE(?String51),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(16,63,8,10),USE(?String52),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(24,63,8,10),USE(?String53),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(33,63,8,10),USE(?String54),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(41,63,8,10),USE(?String55),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(49,63,8,10),USE(?String56),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(57,63,8,10),USE(?String57),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(65,63,8,10),USE(?String58),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(73,63,8,10),USE(?String59),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(8,72,8,10),USE(?String61),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(16,72,8,10),USE(?String62),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(24,72,8,10),USE(?String63),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(33,72,8,10),USE(?String64),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(41,72,8,10),USE(?String65),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(49,72,8,10),USE(?String66),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(57,72,8,10),USE(?String67),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(65,72,8,10),USE(?String68),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(73,72,8,10),USE(?String69),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(8,83,8,10),USE(?String71),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(16,83,8,10),USE(?String72),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(24,83,8,10),USE(?String73),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(33,83,8,10),USE(?String74),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(41,83,8,10),USE(?String75),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(49,83,8,10),USE(?String76),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(57,83,8,10),USE(?String77),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(65,83,8,10),USE(?String78),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(73,83,8,10),USE(?String79),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(8,93,8,10),USE(?String81),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(16,93,8,10),USE(?String82),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(24,93,8,10),USE(?String83),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(33,93,8,10),USE(?String84),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(41,93,8,10),USE(?String85),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(49,93,8,10),USE(?String86),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(57,93,8,10),USE(?String87),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(65,93,8,10),USE(?String88),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(73,93,8,10),USE(?String89),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(8,102,8,10),USE(?String91),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(16,102,8,10),USE(?String92),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(24,102,8,10),USE(?String93),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(33,102,8,10),USE(?String94),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(41,102,8,10),USE(?String95),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(49,102,8,10),USE(?String96),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(57,102,8,10),USE(?String97),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(65,102,8,10),USE(?String98),TRN,CENTER,FONT(,8,COLOR:Maroon,)
STRING('8'),AT(73,102,8,10),USE(?String99),TRN,CENTER,FONT(,8,COLOR:Maroon,)
CHECK('Show Posibles'),AT(11,117),USE(ShowAll)
STRING('String 90'),AT(85,116,60,10),USE(?Result_Str),CENTER,FONT(,,COLOR:Navy,FONT:bold)
PROGRESS,USE(Progress1),AT(1,127,145,3),RANGE(0,100)
PANEL,AT(8,82,25,30),USE(?Panel31),BEVEL(1,-1)
PANEL,AT(32,82,25,30),USE(?Panel32),BEVEL(1,-1)
PANEL,AT(56,82,25,30),USE(?Panel33),BEVEL(1,-1)
BUTTON('POE Cubes'),AT(91,33,42,8),USE(?POEs_Btn),FONT(,10,,)
BUTTON('POE Rows'),AT(91,42,42,8),USE(?POEr_Btn),FONT(,10,,)
BUTTON('POE Colums'),AT(91,51,42,8),USE(?POEc_Btn),FONT(,10,,)
BUTTON('Brute'),AT(91,24,42,8),USE(?Brute_Btn),FONT(,10,,)
BUTTON('Pair Locks'),AT(91,60,42,8),USE(?PairLock_Btn),FONT(,10,,)
BUTTON('Row Combos'),AT(91,78,42,8),USE(?COMBORow_Btn),FONT(,10,,)
BUTTON('Col. Combos'),AT(91,69,42,8),USE(?COMBOCol_Btn),FONT(,10,,)
BUTTON('Cube Combos'),AT(91,87,42,8),USE(?COMBOCube_Btn),FONT(,10,,)
BUTTON('8 Row Combos'),AT(91,96,42,8),USE(?Combo8Row_Btn),FONT(,10,,)
END
CODE
OPEN(Window)
ProgressFEQ = ?Progress1
StFEQ = ?String11-1
DO DisplayGrid
ACCEPT
IF EVENT() = EVENT:Accepted
DO DisplayGrid
DidSomething = False
P += 1
Z = CheckDone()
IF ~Z THEN BREAK.
CASE ACCEPTED()
OF ?Brute_Btn
DO BruteForceCheck
IF ~Z THEN BREAK.
OF ?POEr_Btn
DO POERowsCheck
OF ?POEc_Btn
DO POEColsCheck
OF ?POEs_Btn
DO POECubesCheck
OF ?COMBORow_Btn
DO RowComboCheck
OF ?COMBOCol_Btn
DO ColComboCheck
OF ?COMBOCube_Btn
DO CubeComboCheck
OF ?PairLock_Btn
DO PairLockChecks
OF ?Combo8Row_Btn
DO TwoRowComboCross
OF ?RunAll
DO BruteForceCheck ! Does any individual Cell have only 1 Thing it can be
IF ~DidSomething
DO POECubesCheck
DO POEColsCheck
DO POERowsCheck
END
IF ~DidSomething
DO PairLockChecks
END
IF ~DidSomething
DO RowComboCheck
DO ColComboCheck
DO CubeComboCheck
END
IF ~DidSomething
DO RowComboCross
END
IF ~DidSomething
DO ColComboCross
END
IF ~DidSomething
DO TwoRowComboCross
END
END!IF Accepted.
IF DidSomething
?Result_Str{Prop:Text} = DidSomething & ' cells hit'
ELSE
?Result_Str{Prop:Text} = 'no effect'
END
END
END!ACCEPT
RETURN P
!==============================================================================
DisplayGrid ROUTINE
LOOP R = 1 TO 81
IF Grid[R].Digit
(StFEQ+R){Prop:Text} = Grid[R].Digit
SETFONT((StFEQ+R),,12,COLOR:Black,FONT:regular )
ELSE
IF ShowAll
(StFEQ+R){Prop:Text} = RemString(R)
ELSE
(StFEQ+R){Prop:Text} = ' '
END
END
DISPLAY((StFEQ+R){Prop:Text})
END
TwoRowComboCross ROUTINE
DATA
CQ1 QUEUE(typComboQ)
END
CQ2 QUEUE(typComboQ)
END
CQ3 QUEUE(typComboQ)
END
CQ4 QUEUE(typComboQ)
END
CQ5 QUEUE(typComboQ)
END
CQ6 QUEUE(typComboQ)
END
CQ7 QUEUE(typComboQ)
END
CQ8 QUEUE(typComboQ)
END
CQ9 QUEUE(typComboQ)
END
C1 BYTE
C2 BYTE
C3 BYTE
C4 BYTE
C5 BYTE
C6 BYTE
StRow byte
CODE
free(cq1)
free(cq2)
free(cq3)
free(cq4)
free(cq5)
free(cq6)
free(cq7)
free(cq8)
free(cq9)
LoadComboQ(CQ1,1,0,0)
LoadComboQ(CQ2,2,0,0)
LoadComboQ(CQ3,3,0,0)
LoadComboQ(CQ4,4,0,0)
LoadComboQ(CQ5,5,0,0)
LoadComboQ(CQ6,6,0,0)
LoadComboQ(CQ7,7,0,0)
LoadComboQ(CQ8,8,0,0)
LoadComboQ(CQ9,9,0,0)
IF ~RECORDS(CQ1) OR ~RECORDS(CQ2) OR ~RECORDS(CQ3) OR ~RECORDS(CQ4) OR ~RECORDS(CQ5) OR ~RECORDS(CQ6)
exit
END
CheckCombinations(CQ1,CQ2,CQ3,CQ4,CQ5,CQ6)
C1 = DeleteUnused(CQ1)
C2 = DeleteUnused(CQ2)
C3 = DeleteUnused(CQ3)
C4 = DeleteUnused(CQ4)
C5 = DeleteUnused(CQ5)
C6 = DeleteUnused(CQ6)
IF C1
DidSomething += TESTGridRow(1,CQ1)
END
IF C2
DidSomething += TESTGridRow(2,CQ2)
END
IF C3
DidSomething += TESTGridRow(3,CQ3)
END
IF C4
DidSomething += TESTGridRow(4,CQ4)
END
IF C5
DidSomething += TESTGridRow(5,CQ5)
END
IF C6
DidSomething += TESTGridRow(6,CQ6)
END
ClearUsedFlags(cq1)
ClearUsedFlags(cq2)
ClearUsedFlags(cq3)
IF ~RECORDS(CQ1) OR ~RECORDS(CQ2) OR ~RECORDS(CQ3) OR ~RECORDS(CQ7) OR ~RECORDS(CQ8) OR ~RECORDS(CQ9)
exit
END
CheckCombinations(CQ1,CQ2,CQ3,CQ7,CQ8,CQ9)
C1 = DeleteUnused(CQ1)
C2 = DeleteUnused(CQ2)
C3 = DeleteUnused(CQ3)
C4 = DeleteUnused(CQ7)
C5 = DeleteUnused(CQ8)
C6 = DeleteUnused(CQ9)
IF C1
DidSomething += TESTGridRow(1,CQ1)
END
IF C2
DidSomething += TESTGridRow(2,CQ2)
END
IF C3
DidSomething += TESTGridRow(3,CQ3)
END
IF C4
DidSomething += TESTGridRow(7,CQ7)
END
IF C5
DidSomething += TESTGridRow(8,CQ8)
END
IF C6
DidSomething += TESTGridRow(9,CQ9)
END
ClearUsedFlags(cq4)
ClearUsedFlags(cq5)
ClearUsedFlags(cq6)
ClearUsedFlags(cq7)
ClearUsedFlags(cq8)
ClearUsedFlags(cq9)
IF ~RECORDS(CQ4) OR ~RECORDS(CQ5) OR ~RECORDS(CQ6) OR ~RECORDS(CQ7) OR ~RECORDS(CQ8) OR ~RECORDS(CQ9)
exit
END
CheckCombinations(CQ4,CQ5,CQ6,CQ7,CQ8,CQ9)
C1 = DeleteUnused(CQ4)
C2 = DeleteUnused(CQ5)
C3 = DeleteUnused(CQ6)
C4 = DeleteUnused(CQ7)
C5 = DeleteUnused(CQ8)
C6 = DeleteUnused(CQ9)
IF C1
DidSomething += TESTGridRow(4,CQ4)
END
IF C2
DidSomething += TESTGridRow(5,CQ5)
END
IF C3
DidSomething += TESTGridRow(6,CQ6)
END
IF C4
DidSomething += TESTGridRow(7,CQ7)
END
IF C5
DidSomething += TESTGridRow(8,CQ8)
END
IF C6
DidSomething += TESTGridRow(9,CQ9)
END
free(cq1)
free(cq2)
free(cq3)
free(cq4)
free(cq5)
free(cq6)
free(cq7)
free(cq8)
free(cq9)
RowComboCross ROUTINE
DATA
CQ1 QUEUE(typComboQ)
END
CQ2 QUEUE(typComboQ)
END
CQ3 QUEUE(typComboQ)
END
C1 BYTE
C2 BYTE
C3 BYTE
StRow byte
CODE
StRow = 1
LOOP
free(cq1)
free(cq2)
free(cq3)
IF StRow>7 THEN BREAK.
LoadComboQ(CQ1,StRow,0,0)
LoadComboQ(CQ2,StRow+1,0,0)
LoadComboQ(CQ3,StRow+2,0,0)
IF ~RECORDS(CQ1) OR ~RECORDS(CQ2) OR ~RECORDS(CQ3)
free(cq1)
free(cq2)
free(cq3)
StRow += 3
CYCLE
END
CheckCombinations(CQ1,CQ2,CQ3)
C1 = DeleteUnused(CQ1)
C2 = DeleteUnused(CQ2)
C3 = DeleteUnused(CQ3)
IF C1
DidSomething += TESTGridRow(StRow,CQ1)
END
IF C2
DidSomething += TESTGridRow(StRow+1,CQ2)
END
IF C3
DidSomething += TESTGridRow(StRow+2,CQ3)
END
free(cq1)
free(cq2)
free(cq3)
StRow += 3
END !LOOP
ColComboCross ROUTINE
DATA
CQ1 QUEUE(typComboQ)
END
CQ2 QUEUE(typComboQ)
END
CQ3 QUEUE(typComboQ)
END
C1 BYTE
C2 BYTE
C3 BYTE
StCol byte
CODE
StCol = 1
LOOP
free(cq1)
free(cq2)
free(cq3)
IF StCol>7 THEN BREAK.
LoadComboQ(CQ1,0,StCol,0)
LoadComboQ(CQ2,0,StCol+1,0)
LoadComboQ(CQ3,0,StCol+2,0)
IF ~RECORDS(CQ1) OR ~RECORDS(CQ2) OR ~RECORDS(CQ3)
free(cq1)
free(cq2)
free(cq3)
StCol += 3
CYCLE
END
CheckCombinations(CQ1,CQ2,CQ3)
C1 = DeleteUnused(CQ1)
C2 = DeleteUnused(CQ2)
C3 = DeleteUnused(CQ3)
IF C1
DidSomething += TESTGridCol(StCol,CQ1)
END
IF C2
DidSomething += TESTGridCol(StCol+1,CQ2)
END
IF C3
DidSomething += TESTGridCol(StCol+2,CQ3)
END
free(cq1)
free(cq2)
free(cq3)
StCol += 3
END !LOOP
!==============================================================================
CubeComboCheck ROUTINE
LOOP Cube = 1 TO 9
LoadComboQ(ComboQ,0,0,Cube)
IF ~RECORDS(ComboQ)
MESSAGE('No Solution for Cube ' & Cube)
EXIT
END
DidSomething += TestGridCube(Cube,ComboQ)
END
!==============================================================================
RowComboCheck ROUTINE
DATA
TestGrid GROUP,DIM(9)
Digits BYTE,DIM(9)
END!GROUP
CODE
LOOP R = 1 TO 9
LoadComboQ(ComboQ,R,0,0)
IF ~RECORDS(ComboQ)
MESSAGE('No Solution for Row ' & R)
EXIT
END
DidSomething += TESTGridRow(R,ComboQ)
END
!==============================================================================
ColComboCheck ROUTINE
DATA
TestGrid GROUP,DIM(9)
Digits BYTE,DIM(9)
END!GROUP
CODE
LOOP C = 1 TO 9
LoadComboQ(ComboQ,0,C,0)
IF ~RECORDS(ComboQ)
MESSAGE('No Solution for Col ' & C)
EXIT
END
DidSomething += TestGridCol(C,ComboQ)
END
!_____________________________________________________________________________
!
!
!_____________________________________________________________________________
!_____________________________________________________________________________
PairLockChecks ROUTINE
DATA
ThisCell STRING(9)
ThatCell STRING(9)
OtherCell STRING(9)
CODE
LOOP Cube = 1 TO 9 ! R :: Cube numbers 1 to 9
LOOP D = 1 TO 9
S[D] = '' ! Clear the Pair checks for this cube.
END
LOOP Cell = 1 TO 9 ! Cell :: Cell numbers 1 to 9 within this Cube
X = CubeCellTOGrid(Cube,Cell)
R = CubeCellToRow(Cube,Cell)
C = CubeCellToCol(Cube,Cell)
IF ~Grid[X].Digit ! Haven't picked one for this yet.
LOOP D = 1 TO 9
IF Grid[X].Digits[D] ! This digit could go here.
IF CheckRow(R,C,D) |
OR CheckCol(R,C,D) |
OR CheckCube(R,C,D)
Grid[X].Digits[D] = 0 ! Cell can not have this digit
ELSE
S[D] = CLIP(S[D]) & Cell ! digit D can go in Cell C
END
END!IF This digit could go here.
END ! Check each digit for this cell.
END!IF ~Grid[X].Digit
END!LOOP Cell
LOOP D = 1 TO 9
IF LEN(CLIP(S[D])) > 3 OR LEN(CLIP(S[D])) < 2 THEN CYCLE.
IF ISINROW(S[D]) ! CLEAR This digit from the rest of the ROW
R = CubeCellTORow(Cube,(0+S[D][1]))
LOOP C = 1 TO 9
X = RowColTOGrid(R,C)
IF ~Grid[X].Digit AND Grid[X].Digits[D] AND RowColToCube(R,C)<>Cube
Grid[X].Digits[D]=0
DidSomething += 1
END
END
END
IF ISINCOL(S[D]) ! CLEAR This digit from the rest of the Col.
C = CubeCellTOCol(Cube,(0+S[D][1]))
LOOP R = 1 TO 9
X = RowColTOGrid(R,C)
IF ~Grid[X].Digit AND Grid[X].Digits[D] AND RowColToCube(R,C)<>Cube
Grid[X].Digits[D]=0
DidSomething += 1
END
END
END
IF LEN(CLIP(S[D])) = 2 ! ONLY 2 Cells this digit can go in.
ThisCell = RemString( CubeCellTOGrid(Cube,0+SUB(S[D],1,1)) ) ! Pull everything that can go in Cell 1
OtherCell = RemString( CubeCellTOGrid(Cube,0+SUB(S[D],2,1)) ) ! Pull everything that can go in Cell 2
IF ThisCell = OtherCell and LEN(CLIP(ThisCell))=2 AND LEN(CLIP(OtherCell))=2
! Clear these two digits from the rest of the cells in this cube
LOOP C = 1 TO 9
IF C <> (0+SUB(S[D],1,1)) AND C <> (0+SUB(S[D],2,1))
X = CubeCellTOGrid(Cube,C)
IF GRID[X].Digits[(0+ThisCell[1])]
GRID[X].Digits[(0+ThisCell[1])] = 0
DidSomething += 1
END
IF GRID[X].Digits[(0+ThisCell[2])]
GRID[X].Digits[(0+ThisCell[2])] = 0
DidSomething += 1
END
END
END
END
END
IF LEN(CLIP(S[D])) = 3 ! ONLY 3 Cells this digit can go in.
ThisCell = RemString( CubeCellTOGrid(Cube,0+SUB(S[D],1,1)) ) ! Pull everything that can go in Cell 1
ThatCell = RemString( CubeCellTOGrid(Cube,0+SUB(S[D],2,1)) ) ! Pull everything that can go in Cell 2
OtherCell = RemString( CubeCellTOGrid(Cube,0+SUB(S[D],3,1)) ) ! Pull everything that can go in Cell 3
IF ThisCell = OtherCell AND ThatCell = OtherCell AND LEN(CLIP(ThisCell))=2 AND LEN(CLIP(ThatCell))=2 AND LEN(CLIP(OtherCell))=2
! Clear these two digits from the rest of the cells in this cube
LOOP C = 1 TO 9
IF C <> (0+SUB(S[D],1,1)) AND C <> (0+SUB(S[D],2,1)) AND C <> (0+SUB(S[D],3,1))
X = CubeCellTOGrid(Cube,C)
IF GRID[X].Digits[(0+ThisCell[1])]
GRID[X].Digits[(0+ThisCell[1])] = 0
DidSomething += 1
END
IF GRID[X].Digits[(0+ThisCell[2])]
GRID[X].Digits[(0+ThisCell[2])] = 0
DidSomething += 1
END
IF GRID[X].Digits[(0+ThisCell[3])]
GRID[X].Digits[(0+ThisCell[3])] = 0
DidSomething += 1
END
END
END
END
END
! Check for two digits confined to the same two cells.
IF D<8 AND LEN(CLIP(S[D])) = 2 ! ONLY 2 Cells this digit can go in.
LOOP C = (D+1) TO 9 ! Process the rest & look for a match
IF LEN(CLIP(S[C])) = 2 AND S[C]=S[D] ! Nothing BUT these two digits can go in these two cells.
X = CubeCellTOGrid( Cube, (0+SUB(S[C],1,1)) )
LOOP Y = 1 TO 9 ! Clear any other digits
IF Grid[X].Digits[Y] AND Y<>D AND Y<>C ! out of these two cells.
Grid[X].Digits[Y] = 0
DidSomething += 1
END
END
(StFEQ+X){Prop:Text} = C&D
DISPLAY((StFEQ+X))
X = CubeCellTOGrid( Cube, (0+SUB(S[C],2,1)) )
LOOP Y = 1 TO 9
IF Grid[X].Digits[Y] AND Y<>D AND Y<>C
Grid[X].Digits[Y] = 0
DidSomething += 1
END
END
(StFEQ+X){Prop:Text} = C&D
DISPLAY((StFEQ+X))
END
END
END
END
END!LOOP Cube
!_____________________________________________________________________________
! Check every digit in each cube and if only one cell is left
! where that digit can go, set that cell.
!_____________________________________________________________________________
!_____________________________________________________________________________
POECubesCheck ROUTINE
LOOP CUBE = 1 TO 9 ! Cube :: Cube numbers 1 to 9
LOOP D = 1 TO 9
POSDigits[D] = 0 ! Clear the Process of elimination checks for this row.
END
LOOP Cell = 1 TO 9 ! Cell :: Cell numbers 1 to 9 within this Cube
X = CubeCellTOGrid(Cube,Cell)
R = CubeCellToRow(Cube,Cell)
C = CubeCellToCol(Cube,Cell)
IF ~Grid[X].Digit ! Haven't picked one for this yet.
LOOP D = 1 TO 9
IF Grid[X].Digits[D] ! This digit could go here.
IF CheckRow(R,C,D) |
OR CheckCol(R, C, D) |
OR CheckCube(R,C, D)
Grid[X].Digits[D] = 0 ! Cell can not have this digit
DidSomething += 1
ELSE
IF POSDigits[D] ! but it could also have gone
POSDigits[D] = 10 ! somewere else in this Cube
ELSE
POSDigits[D] = Cell ! Tag this cell, to get this #
END
END
END!IF This digit could go here.
END ! Check each digit for this cell.
END!IF ~Grid[X].Digit
END!LOOP Cell
LOOP D = 1 TO 9
IF POSDigits[D] AND POSDigits[D]<10
X = CubeCellTOGrid(Cube,POSDigits[D])
Grid[X].Digit = D
(StFEQ+X){Prop:Text} = D
SETFONT((StFEQ+X),,12,COLOR:Black,FONT:BOLD)
DISPLAY((StFEQ+X))
DidSomething += 1
END
END
END!LOOP R
!_____________________________________________________________________________
! Check every digit in each row and if only one cell is left
! where that digit can go, set that cell.
!_____________________________________________________________________________
!_____________________________________________________________________________
POERowsCheck ROUTINE
LOOP R = 1 TO 9
LOOP D = 1 TO 9
POSDigits[D] = 0 ! Clear the Process of elimination checks for this row.
END
LOOP C = 1 TO 9
X = RowColToGrid(R,C)
IF ~Grid[X].Digit ! Haven't picked one for this yet.
LOOP D = 1 TO 9
IF Grid[X].Digits[D] ! This digit could go here.
IF CheckRow(R, C, D) |
OR CheckCol(R, C, D) |
OR CheckCube(R, C, D)
Grid[X].Digits[D] = 0 ! Cell can not have this digit
DidSomething += 1
ELSE
IF POSDigits[D] ! but it could also have gone
POSDigits[D] = 10 ! somewere else on this row
ELSE
POSDigits[D] = C ! Tag this cell, to get this #
END
END
END!IF This digit could go here.
END ! Check each digit for this cell.
END!IF ~Grid[X].Digit
END!LOOP C
LOOP D = 1 TO 9
IF POSDigits[D] AND POSDigits[D]<10
X = RowColToGrid(R,POSDigits[D])
Grid[X].Digit = D
(StFEQ+X){Prop:Text} = D
SETFONT((StFEQ+X),,12,COLOR:Black,FONT:BOLD)
DISPLAY((StFEQ+X))
DidSomething += 1
END
END
END!LOOP R
!_____________________________________________________________________________
! Check every digit in each column and if only one cell is left
! where that digit can go, set that cell.
!_____________________________________________________________________________
!_____________________________________________________________________________
POEColsCheck ROUTINE
LOOP C = 1 TO 9
LOOP D = 1 TO 9
POSDigits[D] = 0 ! Clear the Process of elimination checks for this row.
END
LOOP R = 1 TO 9
X = RowColToGrid(R,C)
IF ~Grid[X].Digit ! Haven't picked one for this yet.
LOOP D = 1 TO 9
IF Grid[X].Digits[D] ! This digit could go here.
IF CheckRow(R, C, D) |
OR CheckCol(R, C, D) |
OR CheckCube(R, C, D)
Grid[X].Digits[D] = 0 ! Cell can not have this digit
DidSomething += 1
ELSE
IF POSDigits[D] ! but it could also have gone
POSDigits[D] = 10 ! somewere else on this Column
ELSE
POSDigits[D] = R ! Tag this cell, to get this #
END
END
END!IF This digit could go here.
END ! Check each digit for this cell.
END!IF ~Grid[X].Digit
END!LOOP C
LOOP D = 1 TO 9
IF POSDigits[D] AND POSDigits[D]<10
X = RowColToGrid(POSDigits[D],C)
Grid[X].Digit = D
(StFEQ+X){Prop:Text} = D
SETFONT((StFEQ+X),,12,COLOR:Black,FONT:BOLD)
DISPLAY((StFEQ+X))
DidSomething += 1
END
END
END!LOOP C
!_____________________________________________________________________________
! for every Cell eliminate any digits already fixed
! in that cell's row, column, or cube and if only one
! possible digit remains, set that cell.
!_____________________________________________________________________________
!_____________________________________________________________________________
BruteForceCheck ROUTINE
LOOP R = 1 TO 9
LOOP C = 1 TO 9
X = RowColToGrid(R, C)
IF ~Grid[X].Digit
LOOP D = 1 TO 9
IF Grid[X].Digits[D]
IF CheckRow(R, C, D) |
OR CheckCol(R, C, D) |
OR CheckCube(R, C, D)
Grid[X].Digits[D] = 0 ! Cell can not have this digit
DidSomething += 1
END!IF
F = 0
LOOP Y = 1 TO 9
IF Grid[X].Digits[Y]
IF F
F = 0
BREAK
ELSE
F = Y
END!IF
END!IF
END!LOOP
IF F
Grid[X].Digit = F
(StFEQ+X){Prop:Text} = F
SETFONT((StFEQ+X),,12,COLOR:Black,FONT:BOLD)
DISPLAY((StFEQ+X){Prop:Text})
DidSomething += 1
BREAK
END!IF
END!IF
END!LOOP
END!IF ~Grid[X].Digit
END!LOOP Columns
END!LOOP Rows
!_____________________________________________________________________________________
! Math utility functions for translating Rows, Columns, Cubes, Cells, & Grid #s
!_____________________________________________________________________________________
!_____________________________________________________________________________________
! Translating Cube # and Cell # to Row # and Col. # (do the math)
! Row # = 1 + 3 * INT((Cube#-1)/3) + INT((Cell#-1)/3)
! Col # = 1 + 3 * ((Cube#-1)%3) + ((Cell#-1)%3)
CubeCellTOGrid PROCEDURE(BYTE pCube,BYTE pCell)!,byte grid #
CODE
RETURN ((3*INT((pCube-1)/3)+INT((pCell-1)/3))*9 + 1+3*((pCube-1)%3)+((pCell-1)%3))
CubeCellTORow PROCEDURE(BYTE pCube,BYTE pCell)!,byte row #
CODE
RETURN (1 + 3 * INT((pCube-1)/3) + INT((pCell-1)/3))
CubeCellTOCol PROCEDURE(BYTE pCube,BYTE pCell)!,byte row #
CODE
RETURN (1 + 3 * ((pCube-1)%3) + ((pCell-1)%3))
RowColToCube PROCEDURE(BYTE pR,BYTE pC)!,byte Cube #
CODE
RETURN (3*INT((pR-1)/3)+INT((pC-1)/3)+1)
RowColToGrid PROCEDURE(BYTE pR,BYTE pC)!,Byte Grid #
CODE
RETURN ((pR-1)*9 + pC)
To: restornu
You have to use Occam's Santoku!
12
posted on
08/29/2006 9:35:21 AM PDT
by
Tijeras_Slim
(Where did I leave my matches?)
To: taxcontrol
Also - prove true or false When A = R, the diagonals will always include at least 1 duplicate number If you have a diagonal, top left to bottom right of 123456789, and you have a diagonal from bottom left to top right of 372859416, both those diagonals don't repeat, and should allow you to fill in the remaining blocks for a valid sudoku puzzle.
Here is a valid puzzle with no diagonal repeats:
147925836
528364917
963187452
615439278
789251364
234876591
892613745
471592683
356748129
13
posted on
08/29/2006 9:35:48 AM PDT
by
Koblenz
(Holland: a very tolerant country. Until someone shoots you on a public street in broad daylight...)
To: LesbianThespianGymnasticMidget
14
posted on
08/29/2006 9:35:56 AM PDT
by
Tijeras_Slim
(Where did I leave my matches?)
To: ecurbh
15
posted on
08/29/2006 9:36:43 AM PDT
by
HairOfTheDog
(Head On. Apply directly to the forehead!)
To: LesbianThespianGymnasticMidget
It will take me some time to dig through this as it is more of a program than a proof. Is this Visual Basic or pseudo code?
To: LesbianThespianGymnasticMidget
Damn, you beat me to it. :P
To: LesbianThespianGymnasticMidget
Are you absolutely sure that line 289 is correct?
To: Tijeras_Slim
Just try solving this one. It is the hardest one known.
Line1 STRING('7 8 3 ')
Line2 STRING(' 2 1 ')
Line3 STRING('5 ')
Line4 STRING(' 4 26')
Line5 STRING('3 8 ')
Line6 STRING(' 1 9 ')
Line7 STRING(' 9 6 4')
Line8 STRING(' 7 5 ')
Line9 STRING(' ')
To: LesbianThespianGymnasticMidget
This is how I feel about now....
20
posted on
08/29/2006 9:42:22 AM PDT
by
Tijeras_Slim
(Where did I leave my matches?)
Navigation: use the links below to view more comments.
first 1-20, 21-40, 41-60, 61-80 ... 101-105 next last
Disclaimer:
Opinions posted on Free Republic are those of the individual
posters and do not necessarily represent the opinion of Free Republic or its
management. All materials posted herein are protected by copyright law and the
exemption for fair use of copyrighted works.
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson