 Author Topic: Soduko Thing  (Read 171 times)

Gorlock

• Sr. Member
•    • Posts: 337
•  Soduko Thing
« on: February 19, 2013, 07:20:22 PM »
Hey, I was working on a program to solve Soduko puzzles and I stumbled across online a recursive way to do it. It seems to me like it should work but it isnt. It doesn't even have an error message it just closes and it shouldnt be. It is terminating in the "puzzle = solve(1, 1)" line.

Code: [Select]
_TITLE "Soduko Solver"
SCREEN 12
GOSUB makebg
DO
REDIM SHARED puzzle(9, 9)

puzzle(1, 1) = 0
puzzle(1, 2) = 0
puzzle(1, 3) = 0
puzzle(1, 4) = 4
puzzle(1, 5) = 0
puzzle(1, 6) = 9
puzzle(1, 7) = 0
puzzle(1, 8) = 0
puzzle(1, 9) = 0
puzzle(2, 1) = 2
puzzle(2, 2) = 8
puzzle(2, 3) = 7
puzzle(2, 4) = 0
puzzle(2, 5) = 0
puzzle(2, 6) = 5
puzzle(2, 7) = 6
puzzle(2, 8) = 0
puzzle(2, 9) = 4
puzzle(3, 1) = 0
puzzle(3, 2) = 0
puzzle(3, 3) = 0
puzzle(3, 4) = 8
puzzle(3, 5) = 6
puzzle(3, 6) = 0
puzzle(3, 7) = 3
puzzle(3, 8) = 0
puzzle(3, 9) = 2
puzzle(4, 1) = 0
puzzle(4, 2) = 7
puzzle(4, 3) = 0
puzzle(4, 4) = 3
puzzle(4, 5) = 0
puzzle(4, 6) = 6
puzzle(4, 7) = 0
puzzle(4, 8) = 4
puzzle(4, 9) = 0
puzzle(5, 1) = 0
puzzle(5, 2) = 3
puzzle(5, 3) = 9
puzzle(5, 4) = 0
puzzle(5, 5) = 0
puzzle(5, 6) = 0
puzzle(5, 7) = 8
puzzle(5, 8) = 6
puzzle(5, 9) = 0
puzzle(6, 1) = 0
puzzle(6, 2) = 6
puzzle(6, 3) = 0
puzzle(6, 4) = 9
puzzle(6, 5) = 0
puzzle(6, 6) = 8
puzzle(6, 7) = 0
puzzle(6, 8) = 1
puzzle(6, 9) = 0
puzzle(7, 1) = 4
puzzle(7, 2) = 0
puzzle(7, 3) = 5
puzzle(7, 4) = 0
puzzle(7, 5) = 8
puzzle(7, 6) = 1
puzzle(7, 7) = 0
puzzle(7, 8) = 0
puzzle(7, 9) = 0
puzzle(8, 1) = 6
puzzle(8, 2) = 0
puzzle(8, 3) = 3
puzzle(8, 4) = 2
puzzle(8, 5) = 0
puzzle(8, 6) = 0
puzzle(8, 7) = 7
puzzle(8, 8) = 8
puzzle(8, 9) = 1
puzzle(9, 1) = 0
puzzle(9, 2) = 0
puzzle(9, 3) = 0
puzzle(9, 4) = 6
puzzle(9, 5) = 0
puzzle(9, 6) = 3
puzzle(9, 7) = 0
puzzle(9, 8) = 0
puzzle(9, 9) = 0

DO
_LIMIT 64
GOSUB board
COLOR 15, 0
LOCATE 1, 1
PRINT "Enter what you know then press Enter"
k\$ = INKEY\$
IF k\$ >= CHR\$(49) AND k\$ <= CHR\$(57) THEN puzzle(xsector, ysector) = VAL(k\$)
IF k\$ = CHR\$(8) THEN puzzle(xsector, ysector) = 0
IF k\$ = (CHR\$(0) + CHR\$(80)) THEN ysector = ysector + 1
IF k\$ = (CHR\$(0) + CHR\$(72)) THEN ysector = ysector - 1
IF k\$ = (CHR\$(0) + CHR\$(77)) THEN xsector = xsector + 1
IF k\$ = (CHR\$(0) + CHR\$(75)) THEN xsector = xsector - 1
IF NOT (xsector = 0 AND ysector = 0) THEN
IF xsector < 1 THEN xsector = 1
IF xsector > 9 THEN xsector = 9
IF ysector < 1 THEN ysector = 1
IF ysector > 9 THEN ysector = 9
END IF
DO WHILE _MOUSEINPUT
IF _MOUSEBUTTON(1) THEN
x = _MOUSEX
y = _MOUSEY
DO
xsector = INT((x - 144) / 32)
IF xsector < 1 OR xsector > 9 THEN
xsector = 0
ysector = 0
EXIT DO
END IF
ysector = INT((y - 64) / 32)
IF ysector < 1 OR ysector > 9 THEN
xsector = 0
ysector = 0
EXIT DO
END IF
EXIT DO
LOOP
END IF
LOOP
_DISPLAY
LOOP UNTIL k\$ = CHR\$(13) OR k\$ = CHR\$(27)
IF k\$ = CHR\$(27) THEN SYSTEM
xsector = 0
ysector = 0

puzzle = solve(1, 1)

GOSUB board
COLOR 15, 0
LOCATE 1, 1
IF puzzle = -1 THEN PRINT "The puzzle has been completed"
IF puzzle = 0 THEN
PRINT "This puzzle was either unsolvable or required guesswork"
PRINT "I have solved it as far as I can"
END IF
PRINT
PRINT "Press Escape to exit, Enter to do another puzzle"
_DISPLAY
DO
_LIMIT 64
k\$ = INKEY\$
LOOP UNTIL k\$ = CHR\$(13) OR k\$ = CHR\$(27)
LOOP UNTIL k\$ = CHR\$(27)
SYSTEM

board:
PCOPY 1, 0
xprint = 0
yprint = 0
DO
FOR printx = 182 TO 470 STEP 32
xprint = xprint + 1
IF xprint = 10 THEN EXIT DO
yprint = 0
DO
FOR printy = 105 TO 393 STEP 32
yprint = yprint + 1
IF yprint = 10 THEN EXIT DO
IF (((printx - 182) / 32) + 1) = xsector AND (((printy - 105) / 32) + 1) = ysector THEN
COLOR 0, 15
PAINT (printx, printy), 15, 7
ELSE
COLOR 15, 0
END IF
_PRINTMODE _KEEPBACKGROUND
IF puzzle(xprint, yprint) <> 0 THEN _PRINTSTRING (printx, printy), STR\$(puzzle(xprint, yprint))
NEXT printy
EXIT DO
LOOP
NEXT printx
EXIT DO
LOOP
RETURN

makebg:
FOR drawx = 176 TO 464 STEP 32
PSET (drawx, 96), 7
DRAW "D289"
NEXT drawx
FOR drawy = 96 TO 384 STEP 32
PSET (176, drawy), 7
DRAW "R289"
NEXT drawy
FOR darken1x = 175 TO 463 STEP 96
PSET (darken1x, 96), 7
DRAW "D288"
NEXT darken1x
FOR darken2x = 177 TO 465 STEP 96
PSET (darken2x, 96), 7
DRAW "D288"
NEXT darken2x
FOR darken1y = 95 TO 383 STEP 96
PSET (176, darken1y), 7
DRAW "R288"
NEXT darken1y
FOR darken2y = 97 TO 385 STEP 96
PSET (176, darken2y), 7
DRAW "R288"
NEXT darken2y
PCOPY 0, 1
RETURN

FUNCTION checkRow (row, num)
checkRow = -1
FOR col = 1 TO 9
IF puzzle(row, col) = num THEN checkRow = 0
NEXT col
END FUNCTION

FUNCTION checkCol (col, num)
checkCol = -1
FOR row = 1 TO 9
IF puzzle(row, col) = num THEN checkCol = 0
NEXT row
END FUNCTION

FUNCTION checkBox (row, col, num)
checkBox = -1
row = INT((row / 3)) * 3
col = INT((col / 3)) * 3
FOR r = 1 TO 3
FOR c = 1 TO 3
IF puzzle((row + r), (col + c)) = num THEN checkBox = 0
NEXT c, r
END FUNCTION

FUNCTION solve (row, col)
solve = -1
IF row > 9 THEN EXIT FUNCTION
IF puzzle(row, col) > 0 THEN
IF col < 9 THEN
puzzle = solve(row, (col + 1))
ELSE
puzzle = solve((row + 1), 1)
END IF
ELSE
FOR num = 1 TO 9
IF checkRow(row, num) AND checkCol(col, num) AND checkBox(row, col, num) THEN
puzzle(row, col) = num
IF col < 9 THEN
puzzle = solve(row, (col + 1))
ELSE
puzzle = solve((row + 1), 1)
END IF
END IF
NEXT num
puzzle(row, col) = 0
solve = 0
END IF
END FUNCTION

I included a puzzle in there so you don't have to enter one, it is a valid puzzle. What is happening and why is it closing?

EDIT:
Here is the source (in Java): http://www.heimetli.ch/ffh/simplifiedsudoku.html
There might be something wrong with the throws terminating it but not in QB64, i dont know.
« Last Edit: February 19, 2013, 07:34:47 PM by Gorlock »

LINUXQB64gltester

• Full Member
•   • Posts: 240
•  Re: Soduko Thing
« Reply #1 on: February 20, 2013, 06:15:41 AM »
I had been trying this, but got "side tracked", it dose just close as you say, but I am baffled as to why, sorry, can't be of more help, but anyway, wanted to let you know someone is looking at it,
glad to see something interesting get posted.
For off topic discussions :
Non-QB64 Related Discussion Forum
Also
My Experimenting Forum
"QB64 has a great future!"

OlDosLover

• Hero Member
•     • Posts: 3859
• OlDosLover
•  Re: Soduko Thing
« Reply #2 on: February 20, 2013, 07:46:26 AM »
Hi all,
It seems to crash at the puzzle = solve(1, 1) , as it doesnt return from here.
Code: [Select]
IF k\$ = CHR\$(27) THEN SYSTEM
BEEP: dummy\$ = INPUT\$(1) '***********************************
puzzle = solve(1, 1)
BEEP: dummy\$ = INPUT\$(1) '***********************************
OlDosLover.

Gorlock

• Sr. Member
•    • Posts: 337
•  Re: Soduko Thing
« Reply #3 on: February 20, 2013, 09:57:37 AM »
Yes it is crashing somewhere in there but there is so much going on in that line because it is recursive, it could be anything. I just don't understand why it is closing without an error or anything.

SMcNeill

• Hero Member
•     • Posts: 2414
•  Re: Soduko Thing
« Reply #4 on: February 20, 2013, 10:39:16 AM »
The problem is in your checkbox function.

Code: [Select]
FUNCTION checkBox (row, col, num)
checkBox = -1
row = INT((row / 3)) * 3
col = INT((col / 3)) * 3
FOR r = 1 TO 3
FOR c = 1 TO 3
IF puzzle((row + r), (col + c)) = num THEN checkBox = 0
NEXT c, r
END FUNCTION

Notice how row and col are both in your paramater list, thus they're linked to the function call and if they change in the function, they change in the procedure that called the function.

In the function solve, you have:
Code: [Select]
IF checkRow(row, num) AND checkCol(col, num) AND checkBox(row, col, num) THEN

Up until checkBox is called, row and col are 1, 1.   After it's called, they become 0,0.

Then you
Code: [Select]
IF col < 9 THEN
puzzle = solve(row, (col + 1))

0 is always going to be less than 9, so you are now stuck in an endless recursive loop.   You basically crash when you run out of stack space and die a horrible death.

Change the function checkbox to use temp variables and then give it a go from there.   I won't swear there isn't other problems, but always trying to solve (0,1) is what's causing the endless loop which crashes the program.
http://bit.ly/TextImage -- Library of QB64 code to manipulate text and images, as a BM library.
http://bit.ly/Color32 -- A set of color CONST for use in 32 bit mode, as a BI library.

http://bit.ly/DataToDrive - A set of routines to quickly and easily get data to and from the disk.  BI and BM files

SMcNeill

• Hero Member
•     • Posts: 2414
•  Re: Soduko Thing
« Reply #5 on: February 20, 2013, 10:42:28 AM »
Change it to:
Code: [Select]
FUNCTION checkBox (row, col, num)
checkBox = -1
row1 = INT((row / 3)) * 3
col1 = INT((col / 3)) * 3
FOR r = 1 TO 3
FOR c = 1 TO 3
IF puzzle((row1 + r), (col1 + c)) = num THEN checkBox = 0
NEXT c, r
END FUNCTION

Running it after this point and you no longer get the crash.  It doesn't solve the puzzle, but it doesn't crash anymore... I ran it again after filling in all the blanks in the puzzle except for the last piece, and then let it solve it.   It solved it (according to it), but didn't bother to display the answer for me.   The dern thing is a tease!!
« Last Edit: February 20, 2013, 10:54:42 AM by SMcNeill »
http://bit.ly/TextImage -- Library of QB64 code to manipulate text and images, as a BM library.
http://bit.ly/Color32 -- A set of color CONST for use in 32 bit mode, as a BI library.

http://bit.ly/DataToDrive - A set of routines to quickly and easily get data to and from the disk.  BI and BM files

Gorlock

• Sr. Member
•    • Posts: 337
•  Re: Soduko Thing
« Reply #6 on: February 20, 2013, 11:54:05 AM »
Thank you SMcNeill Code: [Select]
_TITLE "Soduko Solver"
SCREEN 12
GOSUB makebg

DIM SHARED p

DO
REDIM SHARED puzzle(9, 9)

puzzle(1, 1) = 0
puzzle(1, 2) = 0
puzzle(1, 3) = 0
puzzle(1, 4) = 4
puzzle(1, 5) = 0
puzzle(1, 6) = 9
puzzle(1, 7) = 0
puzzle(1, 8) = 0
puzzle(1, 9) = 0
puzzle(2, 1) = 2
puzzle(2, 2) = 8
puzzle(2, 3) = 7
puzzle(2, 4) = 0
puzzle(2, 5) = 0
puzzle(2, 6) = 5
puzzle(2, 7) = 6
puzzle(2, 8) = 0
puzzle(2, 9) = 4
puzzle(3, 1) = 0
puzzle(3, 2) = 0
puzzle(3, 3) = 0
puzzle(3, 4) = 8
puzzle(3, 5) = 6
puzzle(3, 6) = 0
puzzle(3, 7) = 3
puzzle(3, 8) = 0
puzzle(3, 9) = 2
puzzle(4, 1) = 0
puzzle(4, 2) = 7
puzzle(4, 3) = 0
puzzle(4, 4) = 3
puzzle(4, 5) = 0
puzzle(4, 6) = 6
puzzle(4, 7) = 0
puzzle(4, 8) = 4
puzzle(4, 9) = 0
puzzle(5, 1) = 0
puzzle(5, 2) = 3
puzzle(5, 3) = 9
puzzle(5, 4) = 0
puzzle(5, 5) = 0
puzzle(5, 6) = 0
puzzle(5, 7) = 8
puzzle(5, 8) = 6
puzzle(5, 9) = 0
puzzle(6, 1) = 0
puzzle(6, 2) = 6
puzzle(6, 3) = 0
puzzle(6, 4) = 9
puzzle(6, 5) = 0
puzzle(6, 6) = 8
puzzle(6, 7) = 0
puzzle(6, 8) = 1
puzzle(6, 9) = 0
puzzle(7, 1) = 4
puzzle(7, 2) = 0
puzzle(7, 3) = 5
puzzle(7, 4) = 0
puzzle(7, 5) = 8
puzzle(7, 6) = 1
puzzle(7, 7) = 0
puzzle(7, 8) = 0
puzzle(7, 9) = 0
puzzle(8, 1) = 6
puzzle(8, 2) = 0
puzzle(8, 3) = 3
puzzle(8, 4) = 2
puzzle(8, 5) = 0
puzzle(8, 6) = 0
puzzle(8, 7) = 7
puzzle(8, 8) = 8
puzzle(8, 9) = 1
puzzle(9, 1) = 0
puzzle(9, 2) = 0
puzzle(9, 3) = 0
puzzle(9, 4) = 6
puzzle(9, 5) = 0
puzzle(9, 6) = 3
puzzle(9, 7) = 0
puzzle(9, 8) = 0
puzzle(9, 9) = 0

DO
_LIMIT 64
GOSUB board
COLOR 15, 0
LOCATE 1, 1
PRINT "Enter what you know then press Enter"
k\$ = INKEY\$
IF k\$ >= CHR\$(49) AND k\$ <= CHR\$(57) THEN puzzle(xsector, ysector) = VAL(k\$)
IF k\$ = CHR\$(8) THEN puzzle(xsector, ysector) = 0
IF k\$ = (CHR\$(0) + CHR\$(80)) THEN ysector = ysector + 1
IF k\$ = (CHR\$(0) + CHR\$(72)) THEN ysector = ysector - 1
IF k\$ = (CHR\$(0) + CHR\$(77)) THEN xsector = xsector + 1
IF k\$ = (CHR\$(0) + CHR\$(75)) THEN xsector = xsector - 1
IF NOT (xsector = 0 AND ysector = 0) THEN
IF xsector < 1 THEN xsector = 1
IF xsector > 9 THEN xsector = 9
IF ysector < 1 THEN ysector = 1
IF ysector > 9 THEN ysector = 9
END IF
DO WHILE _MOUSEINPUT
IF _MOUSEBUTTON(1) THEN
x = _MOUSEX
y = _MOUSEY
DO
xsector = INT((x - 144) / 32)
IF xsector < 1 OR xsector > 9 THEN
xsector = 0
ysector = 0
EXIT DO
END IF
ysector = INT((y - 64) / 32)
IF ysector < 1 OR ysector > 9 THEN
xsector = 0
ysector = 0
EXIT DO
END IF
EXIT DO
LOOP
END IF
LOOP
_DISPLAY
LOOP UNTIL k\$ = CHR\$(13) OR k\$ = CHR\$(27)
IF k\$ = CHR\$(27) THEN SYSTEM
xsector = 0
ysector = 0

puzzle = solve(1, 1)

GOSUB board
COLOR 15, 0
LOCATE 1, 1
IF puzzle = -1 THEN PRINT "The puzzle has been completed"
IF puzzle = 0 THEN
PRINT "This puzzle was either unsolvable or required guesswork"
PRINT "I have solved it as far as I can"
END IF
PRINT
PRINT "Press Escape to exit, Enter to do another puzzle"
PRINT p
_DISPLAY
DO
_LIMIT 64
k\$ = INKEY\$
LOOP UNTIL k\$ = CHR\$(13) OR k\$ = CHR\$(27)
LOOP UNTIL k\$ = CHR\$(27)
SYSTEM

board:
PCOPY 1, 0
xprint = 0
yprint = 0
DO
FOR printx = 182 TO 470 STEP 32
xprint = xprint + 1
IF xprint = 10 THEN EXIT DO
yprint = 0
DO
FOR printy = 105 TO 393 STEP 32
yprint = yprint + 1
IF yprint = 10 THEN EXIT DO
IF (((printx - 182) / 32) + 1) = xsector AND (((printy - 105) / 32) + 1) = ysector THEN
COLOR 0, 15
PAINT (printx, printy), 15, 7
ELSE
COLOR 15, 0
END IF
_PRINTMODE _KEEPBACKGROUND
IF puzzle(xprint, yprint) <> 0 THEN _PRINTSTRING (printx, printy), STR\$(puzzle(xprint, yprint))
NEXT printy
EXIT DO
LOOP
NEXT printx
EXIT DO
LOOP
RETURN

makebg:
FOR drawx = 176 TO 464 STEP 32
PSET (drawx, 96), 7
DRAW "D289"
NEXT drawx
FOR drawy = 96 TO 384 STEP 32
PSET (176, drawy), 7
DRAW "R289"
NEXT drawy
FOR darken1x = 175 TO 463 STEP 96
PSET (darken1x, 96), 7
DRAW "D288"
NEXT darken1x
FOR darken2x = 177 TO 465 STEP 96
PSET (darken2x, 96), 7
DRAW "D288"
NEXT darken2x
FOR darken1y = 95 TO 383 STEP 96
PSET (176, darken1y), 7
DRAW "R288"
NEXT darken1y
FOR darken2y = 97 TO 385 STEP 96
PSET (176, darken2y), 7
DRAW "R288"
NEXT darken2y
PCOPY 0, 1
RETURN

FUNCTION checkRow (row, num)
checkRow = -1
FOR col = 1 TO 9
IF puzzle(row, col) = num THEN checkRow = 0
NEXT col
END FUNCTION

FUNCTION checkCol (col, num)
checkCol = -1
FOR row = 1 TO 9
IF puzzle(row, col) = num THEN checkCol = 0
NEXT row
END FUNCTION

FUNCTION checkBox (row, col, num)
checkBox = -1
rowx = INT((row / 3)) * 3
colx = INT((col / 3)) * 3
FOR r = 1 TO 3
FOR c = 1 TO 3
IF puzzle((rowx + r), (colx + c)) = num THEN checkBox = 0
NEXT c, r
END FUNCTION

FUNCTION solve (row, col)
solve = -1
IF row > 9 THEN EXIT FUNCTION
IF puzzle(row, col) > 0 THEN
IF col < 9 THEN
puzzle = solve(row, (col + 1))
ELSE
puzzle = solve((row + 1), 1)
END IF
ELSE
FOR num = 1 TO 9
IF checkRow(row, num) AND checkCol(col, num) AND checkBox(row, col, num) THEN
puzzle(row, col) = num
IF col < 9 THEN
puzzle = solve(row, (col + 1))
ELSE
puzzle = solve((row + 1), 1)
END IF
END IF
NEXT num
'puzzle(row, col) = 0
p = p + 1
solve = 0
END IF
END FUNCTION

When I comment out that reset code it solves some of the numbers but it stops for some reason after only a couple. It is hard for me to visualize what the recursion is doing, I am only just learning about it in my Java class. If someone could take a look at it that would be great Gorlock

• Sr. Member
•    • Posts: 337
•  Re: Soduko Thing
« Reply #7 on: February 21, 2013, 12:26:13 PM »
Looking at a slowed down version it solves the first column (up and down) up to the 5th one, it starts out with 2 then it changes it to 3 and then to 7. It then (correctly) changes (1, 1) to 3 from 1. At (1, 5) in the context of what it already solved, 2, 3, and 7 would all work, but the answer is 2. Why is it taking the last number that is available instead of the first one? Or is some other processing causing it to move on that I'm missing?

Code: [Select]
_TITLE "Soduko Solver"
SCREEN 12
GOSUB makebg

DIM SHARED xsector, ysector

DO
REDIM SHARED puzzle(9, 9)

puzzle(1, 1) = 0
puzzle(1, 2) = 0
puzzle(1, 3) = 0
puzzle(1, 4) = 4
puzzle(1, 5) = 0
puzzle(1, 6) = 9
puzzle(1, 7) = 0
puzzle(1, 8) = 0
puzzle(1, 9) = 0
puzzle(2, 1) = 2
puzzle(2, 2) = 8
puzzle(2, 3) = 7
puzzle(2, 4) = 0
puzzle(2, 5) = 0
puzzle(2, 6) = 5
puzzle(2, 7) = 6
puzzle(2, 8) = 0
puzzle(2, 9) = 4
puzzle(3, 1) = 0
puzzle(3, 2) = 0
puzzle(3, 3) = 0
puzzle(3, 4) = 8
puzzle(3, 5) = 6
puzzle(3, 6) = 0
puzzle(3, 7) = 3
puzzle(3, 8) = 0
puzzle(3, 9) = 2
puzzle(4, 1) = 0
puzzle(4, 2) = 7
puzzle(4, 3) = 0
puzzle(4, 4) = 3
puzzle(4, 5) = 0
puzzle(4, 6) = 6
puzzle(4, 7) = 0
puzzle(4, 8) = 4
puzzle(4, 9) = 0
puzzle(5, 1) = 0
puzzle(5, 2) = 3
puzzle(5, 3) = 9
puzzle(5, 4) = 0
puzzle(5, 5) = 0
puzzle(5, 6) = 0
puzzle(5, 7) = 8
puzzle(5, 8) = 6
puzzle(5, 9) = 0
puzzle(6, 1) = 0
puzzle(6, 2) = 6
puzzle(6, 3) = 0
puzzle(6, 4) = 9
puzzle(6, 5) = 0
puzzle(6, 6) = 8
puzzle(6, 7) = 0
puzzle(6, 8) = 1
puzzle(6, 9) = 0
puzzle(7, 1) = 4
puzzle(7, 2) = 0
puzzle(7, 3) = 5
puzzle(7, 4) = 0
puzzle(7, 5) = 8
puzzle(7, 6) = 1
puzzle(7, 7) = 0
puzzle(7, 8) = 0
puzzle(7, 9) = 0
puzzle(8, 1) = 6
puzzle(8, 2) = 0
puzzle(8, 3) = 3
puzzle(8, 4) = 2
puzzle(8, 5) = 0
puzzle(8, 6) = 0
puzzle(8, 7) = 7
puzzle(8, 8) = 8
puzzle(8, 9) = 1
puzzle(9, 1) = 0
puzzle(9, 2) = 0
puzzle(9, 3) = 0
puzzle(9, 4) = 6
puzzle(9, 5) = 0
puzzle(9, 6) = 3
puzzle(9, 7) = 0
puzzle(9, 8) = 0
puzzle(9, 9) = 0

DO
_LIMIT 64
CALL board
COLOR 15, 0
LOCATE 1, 1
PRINT "Enter what you know then press Enter"
k\$ = INKEY\$
IF k\$ >= CHR\$(49) AND k\$ <= CHR\$(57) THEN puzzle(xsector, ysector) = VAL(k\$)
IF k\$ = CHR\$(8) THEN puzzle(xsector, ysector) = 0
IF k\$ = (CHR\$(0) + CHR\$(80)) THEN ysector = ysector + 1
IF k\$ = (CHR\$(0) + CHR\$(72)) THEN ysector = ysector - 1
IF k\$ = (CHR\$(0) + CHR\$(77)) THEN xsector = xsector + 1
IF k\$ = (CHR\$(0) + CHR\$(75)) THEN xsector = xsector - 1
IF NOT (xsector = 0 AND ysector = 0) THEN
IF xsector < 1 THEN xsector = 1
IF xsector > 9 THEN xsector = 9
IF ysector < 1 THEN ysector = 1
IF ysector > 9 THEN ysector = 9
END IF
DO WHILE _MOUSEINPUT
IF _MOUSEBUTTON(1) THEN
x = _MOUSEX
y = _MOUSEY
DO
xsector = INT((x - 144) / 32)
IF xsector < 1 OR xsector > 9 THEN
xsector = 0
ysector = 0
EXIT DO
END IF
ysector = INT((y - 64) / 32)
IF ysector < 1 OR ysector > 9 THEN
xsector = 0
ysector = 0
EXIT DO
END IF
EXIT DO
LOOP
END IF
LOOP
_DISPLAY
LOOP UNTIL k\$ = CHR\$(13) OR k\$ = CHR\$(27)
IF k\$ = CHR\$(27) THEN SYSTEM
xsector = 0
ysector = 0

puzzle = solve(1, 1)

CALL board
COLOR 15, 0
LOCATE 1, 1
IF puzzle = -1 THEN PRINT "The puzzle has been completed"
IF puzzle = 0 THEN
PRINT "This puzzle was either unsolvable or required guesswork"
PRINT "I have solved it as far as I can"
END IF
PRINT
PRINT "Press Escape to exit, Enter to do another puzzle"
_DISPLAY
DO
_LIMIT 64
k\$ = INKEY\$
LOOP UNTIL k\$ = CHR\$(13) OR k\$ = CHR\$(27)
LOOP UNTIL k\$ = CHR\$(27)
SYSTEM

makebg:
FOR drawx = 176 TO 464 STEP 32
PSET (drawx, 96), 7
DRAW "D289"
NEXT drawx
FOR drawy = 96 TO 384 STEP 32
PSET (176, drawy), 7
DRAW "R289"
NEXT drawy
FOR darken1x = 175 TO 463 STEP 96
PSET (darken1x, 96), 7
DRAW "D288"
NEXT darken1x
FOR darken2x = 177 TO 465 STEP 96
PSET (darken2x, 96), 7
DRAW "D288"
NEXT darken2x
FOR darken1y = 95 TO 383 STEP 96
PSET (176, darken1y), 7
DRAW "R288"
NEXT darken1y
FOR darken2y = 97 TO 385 STEP 96
PSET (176, darken2y), 7
DRAW "R288"
NEXT darken2y
PCOPY 0, 1
RETURN

SUB board
PCOPY 1, 0
xprint = 0
yprint = 0
DO
FOR printx = 182 TO 470 STEP 32
xprint = xprint + 1
IF xprint = 10 THEN EXIT DO
yprint = 0
DO
FOR printy = 105 TO 393 STEP 32
yprint = yprint + 1
IF yprint = 10 THEN EXIT DO
IF (((printx - 182) / 32) + 1) = xsector AND (((printy - 105) / 32) + 1) = ysector THEN
COLOR 0, 15
PAINT (printx, printy), 15, 7
ELSE
COLOR 15, 0
END IF
_PRINTMODE _KEEPBACKGROUND
IF puzzle(xprint, yprint) <> 0 THEN _PRINTSTRING (printx, printy), STR\$(puzzle(xprint, yprint))
NEXT printy
EXIT DO
LOOP
NEXT printx
EXIT DO
LOOP
END SUB

FUNCTION checkRow (row, num)
checkRow = -1
FOR colx = 1 TO 9
IF puzzle(row, colx) = num THEN checkRow = 0
NEXT colx
END FUNCTION

FUNCTION checkCol (col, num)
checkCol = -1
FOR rowx = 1 TO 9
IF puzzle(rowx, col) = num THEN checkCol = 0
NEXT rowx
END FUNCTION

FUNCTION checkBox (row, col, num)
checkBox = -1
rowx = INT(((row - 1) / 3)) * 3
colx = INT(((col - 1) / 3)) * 3
FOR r = 1 TO 3
FOR c = 1 TO 3
IF puzzle((rowx + r), (colx + c)) = num THEN
checkBox = 0
IF row = 1 AND col = 5 THEN
'                OPEN "his.txt" FOR APPEND AS #1
'                PRINT #1, row, col, num
'                PRINT #1, rowx, colx
'                PRINT #1, r, c
'PRINT #1, ""
'                CLOSE #1
END IF
END IF
NEXT c, r
END FUNCTION

FUNCTION solve (row, col)
solve = -1
IF row > 9 THEN EXIT FUNCTION
IF puzzle(row, col) > 0 THEN
IF col < 9 THEN
puzzle = solve(row, (col + 1))
ELSE
puzzle = solve((row + 1), 1)
END IF
ELSE
FOR num = 1 TO 9
IF row = 1 AND col = 5 THEN
'OPEN "his.txt" FOR APPEND AS #1
'PRINT #1, num
'PRINT #1, checkRow(row, num)
'PRINT #1, checkCol(col, num)
'PRINT #1, checkBox(row, col, num)
'PRINT #1, ""
'CLOSE #1
END IF

IF checkRow(row, num) AND checkCol(col, num) AND checkBox(row, col, num) THEN
puzzle(row, col) = num
CALL board
_DISPLAY
_DELAY 1
IF col < 9 THEN
puzzle = solve(row, (col + 1))
ELSE
puzzle = solve((row + 1), 1)
END IF
END IF
NEXT num
'puzzle(row, col) = 0
solve = 0
END IF
END FUNCTION

EDIT: The reason it can't solve the puzzle is because, when it gets there, there is no valid number for (1, 7). This is because (1, 5) is incorrectly 7 instead of 2. This is why I asked the question above.

EDIT: Sorry, I accidentally posted the wrong code, I replaced it with the correct code.
« Last Edit: February 21, 2013, 01:11:25 PM by Gorlock »

Gorlock

• Sr. Member
•    • Posts: 337
•  Re: Soduko Thing
« Reply #8 on: February 21, 2013, 05:23:58 PM »
I forgot I had commented out that line that resets the value to 0 if it finishes the FOR loop. It can get a lot further but it still isn't solving the puzzles. It can solve the first 6 columns correctly almost but then it backtracks all the way and stops...

Code: [Select]
_TITLE "Soduko Solver"
SCREEN 12
GOSUB makebg

DIM SHARED xsector, ysector

DO
REDIM SHARED puzzle(9, 9)

puzzle(1, 1) = 0
puzzle(1, 2) = 0
puzzle(1, 3) = 0
puzzle(1, 4) = 4
puzzle(1, 5) = 0
puzzle(1, 6) = 9
puzzle(1, 7) = 0
puzzle(1, 8) = 0
puzzle(1, 9) = 0
puzzle(2, 1) = 2
puzzle(2, 2) = 8
puzzle(2, 3) = 7
puzzle(2, 4) = 0
puzzle(2, 5) = 0
puzzle(2, 6) = 5
puzzle(2, 7) = 6
puzzle(2, 8) = 0
puzzle(2, 9) = 4
puzzle(3, 1) = 0
puzzle(3, 2) = 0
puzzle(3, 3) = 0
puzzle(3, 4) = 8
puzzle(3, 5) = 6
puzzle(3, 6) = 0
puzzle(3, 7) = 3
puzzle(3, 8) = 0
puzzle(3, 9) = 2
puzzle(4, 1) = 0
puzzle(4, 2) = 7
puzzle(4, 3) = 0
puzzle(4, 4) = 3
puzzle(4, 5) = 0
puzzle(4, 6) = 6
puzzle(4, 7) = 0
puzzle(4, 8) = 4
puzzle(4, 9) = 0
puzzle(5, 1) = 0
puzzle(5, 2) = 3
puzzle(5, 3) = 9
puzzle(5, 4) = 0
puzzle(5, 5) = 0
puzzle(5, 6) = 0
puzzle(5, 7) = 8
puzzle(5, 8) = 6
puzzle(5, 9) = 0
puzzle(6, 1) = 0
puzzle(6, 2) = 6
puzzle(6, 3) = 0
puzzle(6, 4) = 9
puzzle(6, 5) = 0
puzzle(6, 6) = 8
puzzle(6, 7) = 0
puzzle(6, 8) = 1
puzzle(6, 9) = 0
puzzle(7, 1) = 4
puzzle(7, 2) = 0
puzzle(7, 3) = 5
puzzle(7, 4) = 0
puzzle(7, 5) = 8
puzzle(7, 6) = 1
puzzle(7, 7) = 0
puzzle(7, 8) = 0
puzzle(7, 9) = 0
puzzle(8, 1) = 6
puzzle(8, 2) = 0
puzzle(8, 3) = 3
puzzle(8, 4) = 2
puzzle(8, 5) = 0
puzzle(8, 6) = 0
puzzle(8, 7) = 7
puzzle(8, 8) = 8
puzzle(8, 9) = 1
puzzle(9, 1) = 0
puzzle(9, 2) = 0
puzzle(9, 3) = 0
puzzle(9, 4) = 6
puzzle(9, 5) = 0
puzzle(9, 6) = 3
puzzle(9, 7) = 0
puzzle(9, 8) = 0
puzzle(9, 9) = 0

DO
_LIMIT 64
CALL board
COLOR 15, 0
LOCATE 1, 1
PRINT "Enter what you know then press Enter"
k\$ = INKEY\$
IF k\$ >= CHR\$(49) AND k\$ <= CHR\$(57) THEN puzzle(xsector, ysector) = VAL(k\$)
IF k\$ = CHR\$(8) THEN puzzle(xsector, ysector) = 0
IF k\$ = (CHR\$(0) + CHR\$(80)) THEN ysector = ysector + 1
IF k\$ = (CHR\$(0) + CHR\$(72)) THEN ysector = ysector - 1
IF k\$ = (CHR\$(0) + CHR\$(77)) THEN xsector = xsector + 1
IF k\$ = (CHR\$(0) + CHR\$(75)) THEN xsector = xsector - 1
IF NOT (xsector = 0 AND ysector = 0) THEN
IF xsector < 1 THEN xsector = 1
IF xsector > 9 THEN xsector = 9
IF ysector < 1 THEN ysector = 1
IF ysector > 9 THEN ysector = 9
END IF
DO WHILE _MOUSEINPUT
IF _MOUSEBUTTON(1) THEN
x = _MOUSEX
y = _MOUSEY
DO
xsector = INT((x - 144) / 32)
IF xsector < 1 OR xsector > 9 THEN
xsector = 0
ysector = 0
EXIT DO
END IF
ysector = INT((y - 64) / 32)
IF ysector < 1 OR ysector > 9 THEN
xsector = 0
ysector = 0
EXIT DO
END IF
EXIT DO
LOOP
END IF
LOOP
_DISPLAY
LOOP UNTIL k\$ = CHR\$(13) OR k\$ = CHR\$(27)
IF k\$ = CHR\$(27) THEN SYSTEM
xsector = 0
ysector = 0

puzzle = solve(1, 1)

CALL board
COLOR 15, 0
LOCATE 1, 1
IF puzzle = -1 THEN PRINT "The puzzle has been completed"
IF puzzle = 0 THEN
PRINT "This puzzle was either unsolvable or required guesswork"
PRINT "I have solved it as far as I can"
END IF
PRINT
PRINT "Press Escape to exit, Enter to do another puzzle"
_DISPLAY
DO
_LIMIT 64
k\$ = INKEY\$
LOOP UNTIL k\$ = CHR\$(13) OR k\$ = CHR\$(27)
LOOP UNTIL k\$ = CHR\$(27)
SYSTEM

makebg:
FOR drawx = 176 TO 464 STEP 32
PSET (drawx, 96), 7
DRAW "D289"
NEXT drawx
FOR drawy = 96 TO 384 STEP 32
PSET (176, drawy), 7
DRAW "R289"
NEXT drawy
FOR darken1x = 175 TO 463 STEP 96
PSET (darken1x, 96), 7
DRAW "D288"
NEXT darken1x
FOR darken2x = 177 TO 465 STEP 96
PSET (darken2x, 96), 7
DRAW "D288"
NEXT darken2x
FOR darken1y = 95 TO 383 STEP 96
PSET (176, darken1y), 7
DRAW "R288"
NEXT darken1y
FOR darken2y = 97 TO 385 STEP 96
PSET (176, darken2y), 7
DRAW "R288"
NEXT darken2y
PCOPY 0, 1
RETURN

SUB board
PCOPY 1, 0
xprint = 0
yprint = 0
DO
FOR printx = 182 TO 470 STEP 32
xprint = xprint + 1
IF xprint = 10 THEN EXIT DO
yprint = 0
DO
FOR printy = 105 TO 393 STEP 32
yprint = yprint + 1
IF yprint = 10 THEN EXIT DO
IF (((printx - 182) / 32) + 1) = xsector AND (((printy - 105) / 32) + 1) = ysector THEN
COLOR 0, 15
PAINT (printx, printy), 15, 7
ELSE
COLOR 15, 0
END IF
_PRINTMODE _KEEPBACKGROUND
IF puzzle(xprint, yprint) <> 0 THEN _PRINTSTRING (printx, printy), STR\$(puzzle(xprint, yprint))
NEXT printy
EXIT DO
LOOP
NEXT printx
EXIT DO
LOOP
END SUB

FUNCTION checkRow (row, num)
checkRow = -1
FOR colx = 1 TO 9
IF puzzle(row, colx) = num THEN checkRow = 0
NEXT colx
END FUNCTION

FUNCTION checkCol (col, num)
checkCol = -1
FOR rowx = 1 TO 9
IF puzzle(rowx, col) = num THEN checkCol = 0
NEXT rowx
END FUNCTION

FUNCTION checkBox (row, col, num)
checkBox = -1
rowx = INT(((row - 1) / 3)) * 3
colx = INT(((col - 1) / 3)) * 3
FOR r = 1 TO 3
FOR c = 1 TO 3
IF puzzle((rowx + r), (colx + c)) = num THEN checkBox = 0
NEXT c, r
END FUNCTION

FUNCTION solve (row, col)
solve = -1
IF row > 9 THEN EXIT FUNCTION
IF puzzle(row, col) > 0 THEN
IF col < 9 THEN
puzzle = solve(row, (col + 1))
ELSE
puzzle = solve((row + 1), 1)
END IF
ELSE
FOR num = 1 TO 9
IF checkRow(row, num) AND checkCol(col, num) AND checkBox(row, col, num) THEN
puzzle(row, col) = num
CALL board
_DISPLAY
_DELAY .2
IF col < 9 THEN
puzzle = solve(row, (col + 1))
ELSE
puzzle = solve((row + 1), 1)
END IF
END IF
NEXT num
puzzle(row, col) = 0
solve = 0
END IF
END FUNCTION

Any ideas would be helpful.

EDIT: It actually solves it completely, but when it calls EXIT FUNCTION I think it just EXITs the FUNCTION and steps back one because it is recursive, to an instance where row is no longer > 9. The throw in the Java code would compensate for this but it can't here. I will think of a way to fix this and post the final results.

EDIT: Feel free to use this however you want; public domain. It should work with any soduko puzzle. There are 2 puzzles below you can test it with, just paste the code after the "REDIM puzzle(9, 9)" line. Enjoy Code: [Select]
_TITLE "Soduko Solver"
SCREEN 12
GOSUB makebg
DO
REDIM SHARED puzzle(9, 9)
DIM SHARED finflag
DO
_LIMIT 64
GOSUB board
COLOR 15, 0
LOCATE 1, 1
PRINT "Enter what you know then press Enter"
k\$ = INKEY\$
IF k\$ >= CHR\$(49) AND k\$ <= CHR\$(57) THEN puzzle(xsector, ysector) = VAL(k\$)
IF k\$ = CHR\$(8) THEN puzzle(xsector, ysector) = 0
IF k\$ = (CHR\$(0) + CHR\$(80)) THEN ysector = ysector + 1
IF k\$ = (CHR\$(0) + CHR\$(72)) THEN ysector = ysector - 1
IF k\$ = (CHR\$(0) + CHR\$(77)) THEN xsector = xsector + 1
IF k\$ = (CHR\$(0) + CHR\$(75)) THEN xsector = xsector - 1
IF NOT (xsector = 0 AND ysector = 0) THEN
IF xsector < 1 THEN xsector = 1
IF xsector > 9 THEN xsector = 9
IF ysector < 1 THEN ysector = 1
IF ysector > 9 THEN ysector = 9
END IF
DO WHILE _MOUSEINPUT
IF _MOUSEBUTTON(1) THEN
x = _MOUSEX
y = _MOUSEY
DO
xsector = INT((x - 144) / 32)
IF xsector < 1 OR xsector > 9 THEN
xsector = 0
ysector = 0
EXIT DO
END IF
ysector = INT((y - 64) / 32)
IF ysector < 1 OR ysector > 9 THEN
xsector = 0
ysector = 0
EXIT DO
END IF
EXIT DO
LOOP
END IF
LOOP
_DISPLAY
LOOP UNTIL k\$ = CHR\$(13) OR k\$ = CHR\$(27)
IF k\$ = CHR\$(27) THEN SYSTEM
xsector = 0
ysector = 0
puzzle = solve(1, 1)
finflag = 0
GOSUB board
COLOR 15, 0
LOCATE 1, 1
IF puzzle = -1 THEN PRINT "The puzzle has been completed!"
IF puzzle = 0 THEN
PRINT "This puzzle was unsolvable or an exception has occured!"
END IF
PRINT
PRINT "Press Escape to exit, Enter to do another puzzle"
_DISPLAY
DO
_LIMIT 64
k\$ = INKEY\$
LOOP UNTIL k\$ = CHR\$(13) OR k\$ = CHR\$(27)
LOOP UNTIL k\$ = CHR\$(27)
SYSTEM

makebg:
FOR drawx = 176 TO 464 STEP 32
PSET (drawx, 96), 7
DRAW "D289"
NEXT drawx
FOR drawy = 96 TO 384 STEP 32
PSET (176, drawy), 7
DRAW "R289"
NEXT drawy
FOR darken1x = 175 TO 463 STEP 96
PSET (darken1x, 96), 7
DRAW "D288"
NEXT darken1x
FOR darken2x = 177 TO 465 STEP 96
PSET (darken2x, 96), 7
DRAW "D288"
NEXT darken2x
FOR darken1y = 95 TO 383 STEP 96
PSET (176, darken1y), 7
DRAW "R288"
NEXT darken1y
FOR darken2y = 97 TO 385 STEP 96
PSET (176, darken2y), 7
DRAW "R288"
NEXT darken2y
PCOPY 0, 1
RETURN

board:
PCOPY 1, 0
xprint = 0
yprint = 0
DO
FOR printx = 182 TO 470 STEP 32
xprint = xprint + 1
IF xprint = 10 THEN EXIT DO
yprint = 0
DO
FOR printy = 105 TO 393 STEP 32
yprint = yprint + 1
IF yprint = 10 THEN EXIT DO
IF (((printx - 182) / 32) + 1) = xsector AND (((printy - 105) / 32) + 1) = ysector THEN
COLOR 0, 15
PAINT (printx, printy), 15, 7
ELSE
COLOR 15, 0
END IF
_PRINTMODE _KEEPBACKGROUND
IF puzzle(xprint, yprint) <> 0 THEN _PRINTSTRING (printx, printy), STR\$(puzzle(xprint, yprint))
NEXT printy
EXIT DO
LOOP
NEXT printx
EXIT DO
LOOP
RETURN

FUNCTION checkRow (row, num)
checkRow = -1
FOR colx = 1 TO 9
IF puzzle(row, colx) = num THEN checkRow = 0
NEXT colx
END FUNCTION

FUNCTION checkCol (col, num)
checkCol = -1
FOR rowx = 1 TO 9
IF puzzle(rowx, col) = num THEN checkCol = 0
NEXT rowx
END FUNCTION

FUNCTION checkBox (row, col, num)
checkBox = -1
rowx = INT(((row - 1) / 3)) * 3
colx = INT(((col - 1) / 3)) * 3
FOR r = 1 TO 3
FOR c = 1 TO 3
IF puzzle((rowx + r), (colx + c)) = num THEN checkBox = 0
NEXT c, r
END FUNCTION

FUNCTION solve (row, col)
solve = -1
finflag = row
IF finflag > 9 THEN EXIT FUNCTION
IF puzzle(row, col) > 0 THEN
IF col < 9 THEN
puzzle = solve(row, (col + 1))
ELSE
puzzle = solve((row + 1), 1)
END IF
IF finflag > 9 THEN EXIT FUNCTION
ELSE
FOR num = 1 TO 9
IF checkRow(row, num) AND checkCol(col, num) AND checkBox(row, col, num) THEN
puzzle(row, col) = num
IF col < 9 THEN
puzzle = solve(row, (col + 1))
ELSE
puzzle = solve((row + 1), 1)
END IF
IF finflag > 9 THEN EXIT FUNCTION
END IF
NEXT num
puzzle(row, col) = 0
solve = 0
END IF
END FUNCTION

example easy puzzle
Code: [Select]
puzzle(1, 1) = 0
puzzle(1, 2) = 0
puzzle(1, 3) = 0
puzzle(1, 4) = 4
puzzle(1, 5) = 0
puzzle(1, 6) = 9
puzzle(1, 7) = 0
puzzle(1, 8) = 0
puzzle(1, 9) = 0
puzzle(2, 1) = 2
puzzle(2, 2) = 8
puzzle(2, 3) = 7
puzzle(2, 4) = 0
puzzle(2, 5) = 0
puzzle(2, 6) = 5
puzzle(2, 7) = 6
puzzle(2, 8) = 0
puzzle(2, 9) = 4
puzzle(3, 1) = 0
puzzle(3, 2) = 0
puzzle(3, 3) = 0
puzzle(3, 4) = 8
puzzle(3, 5) = 6
puzzle(3, 6) = 0
puzzle(3, 7) = 3
puzzle(3, 8) = 0
puzzle(3, 9) = 2
puzzle(4, 1) = 0
puzzle(4, 2) = 7
puzzle(4, 3) = 0
puzzle(4, 4) = 3
puzzle(4, 5) = 0
puzzle(4, 6) = 6
puzzle(4, 7) = 0
puzzle(4, 8) = 4
puzzle(4, 9) = 0
puzzle(5, 1) = 0
puzzle(5, 2) = 3
puzzle(5, 3) = 9
puzzle(5, 4) = 0
puzzle(5, 5) = 0
puzzle(5, 6) = 0
puzzle(5, 7) = 8
puzzle(5, 8) = 6
puzzle(5, 9) = 0
puzzle(6, 1) = 0
puzzle(6, 2) = 6
puzzle(6, 3) = 0
puzzle(6, 4) = 9
puzzle(6, 5) = 0
puzzle(6, 6) = 8
puzzle(6, 7) = 0
puzzle(6, 8) = 1
puzzle(6, 9) = 0
puzzle(7, 1) = 4
puzzle(7, 2) = 0
puzzle(7, 3) = 5
puzzle(7, 4) = 0
puzzle(7, 5) = 8
puzzle(7, 6) = 1
puzzle(7, 7) = 0
puzzle(7, 8) = 0
puzzle(7, 9) = 0
puzzle(8, 1) = 6
puzzle(8, 2) = 0
puzzle(8, 3) = 3
puzzle(8, 4) = 2
puzzle(8, 5) = 0
puzzle(8, 6) = 0
puzzle(8, 7) = 7
puzzle(8, 8) = 8
puzzle(8, 9) = 1
puzzle(9, 1) = 0
puzzle(9, 2) = 0
puzzle(9, 3) = 0
puzzle(9, 4) = 6
puzzle(9, 5) = 0
puzzle(9, 6) = 3
puzzle(9, 7) = 0
puzzle(9, 8) = 0
puzzle(9, 9) = 0

example hard puzzle
Code: [Select]
puzzle(1, 1) = 9
puzzle(1, 2) = 0
puzzle(1, 3) = 0
puzzle(1, 4) = 0
puzzle(1, 5) = 5
puzzle(1, 6) = 0
puzzle(1, 7) = 0
puzzle(1, 8) = 0
puzzle(1, 9) = 0
puzzle(2, 1) = 0
puzzle(2, 2) = 5
puzzle(2, 3) = 0
puzzle(2, 4) = 0
puzzle(2, 5) = 0
puzzle(2, 6) = 0
puzzle(2, 7) = 0
puzzle(2, 8) = 1
puzzle(2, 9) = 4
puzzle(3, 1) = 0
puzzle(3, 2) = 4
puzzle(3, 3) = 8
puzzle(3, 4) = 0
puzzle(3, 5) = 0
puzzle(3, 6) = 1
puzzle(3, 7) = 2
puzzle(3, 8) = 0
puzzle(3, 9) = 0
puzzle(4, 1) = 0
puzzle(4, 2) = 0
puzzle(4, 3) = 2
puzzle(4, 4) = 0
puzzle(4, 5) = 4
puzzle(4, 6) = 3
puzzle(4, 7) = 0
puzzle(4, 8) = 0
puzzle(4, 9) = 0
puzzle(5, 1) = 0
puzzle(5, 2) = 8
puzzle(5, 3) = 9
puzzle(5, 4) = 0
puzzle(5, 5) = 0
puzzle(5, 6) = 0
puzzle(5, 7) = 6
puzzle(5, 8) = 4
puzzle(5, 9) = 0
puzzle(6, 1) = 0
puzzle(6, 2) = 0
puzzle(6, 3) = 0
puzzle(6, 4) = 0
puzzle(6, 5) = 9
puzzle(6, 6) = 0
puzzle(6, 7) = 1
puzzle(6, 8) = 0
puzzle(6, 9) = 0
puzzle(7, 1) = 0
puzzle(7, 2) = 0
puzzle(7, 3) = 3
puzzle(7, 4) = 7
puzzle(7, 5) = 0
puzzle(7, 6) = 0
puzzle(7, 7) = 8
puzzle(7, 8) = 9
puzzle(7, 9) = 0
puzzle(8, 1) = 2
puzzle(8, 2) = 6
puzzle(8, 3) = 0
puzzle(8, 4) = 0
puzzle(8, 5) = 0
puzzle(8, 6) = 0
puzzle(8, 7) = 0
puzzle(8, 8) = 3
puzzle(8, 9) = 0
puzzle(9, 1) = 0
puzzle(9, 2) = 0
puzzle(9, 3) = 0
puzzle(9, 4) = 0
puzzle(9, 5) = 3
puzzle(9, 6) = 0
puzzle(9, 7) = 0
puzzle(9, 8) = 0
puzzle(9, 9) = 2
« Last Edit: February 21, 2013, 06:07:28 PM by Gorlock »