### 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 12GOSUB makebgDO    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)SYSTEMboard:PCOPY 1, 0xprint = 0yprint = 0DO    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 DOLOOPRETURNmakebg:FOR drawx = 176 TO 464 STEP 32    PSET (drawx, 96), 7    DRAW "D289"NEXT drawxFOR drawy = 96 TO 384 STEP 32    PSET (176, drawy), 7    DRAW "R289"NEXT drawyFOR darken1x = 175 TO 463 STEP 96    PSET (darken1x, 96), 7    DRAW "D288"NEXT darken1xFOR darken2x = 177 TO 465 STEP 96    PSET (darken2x, 96), 7    DRAW "D288"NEXT darken2xFOR darken1y = 95 TO 383 STEP 96    PSET (176, darken1y), 7    DRAW "R288"NEXT darken1yFOR darken2y = 97 TO 385 STEP 96    PSET (176, darken2y), 7    DRAW "R288"NEXT darken2yPCOPY 0, 1RETURNFUNCTION checkRow (row, num)checkRow = -1FOR col = 1 TO 9    IF puzzle(row, col) = num THEN checkRow = 0NEXT colEND FUNCTIONFUNCTION checkCol (col, num)checkCol = -1FOR row = 1 TO 9    IF puzzle(row, col) = num THEN checkCol = 0NEXT rowEND FUNCTIONFUNCTION checkBox (row, col, num)checkBox = -1row = INT((row / 3)) * 3col = INT((col / 3)) * 3FOR r = 1 TO 3    FOR c = 1 TO 3        IF puzzle((row + r), (col + c)) = num THEN checkBox = 0NEXT c, rEND FUNCTIONFUNCTION solve (row, col)solve = -1IF row > 9 THEN EXIT FUNCTIONIF puzzle(row, col) > 0 THEN    IF col < 9 THEN        puzzle = solve(row, (col + 1))    ELSE        puzzle = solve((row + 1), 1)    END IFELSE    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 = 0END IFEND 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 = -1row = INT((row / 3)) * 3col = INT((col / 3)) * 3FOR r = 1 TO 3    FOR c = 1 TO 3        IF puzzle((row + r), (col + c)) = num THEN checkBox = 0NEXT c, rEND 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 = -1row1 = INT((row / 3)) * 3col1 = INT((col / 3)) * 3FOR r = 1 TO 3    FOR c = 1 TO 3        IF puzzle((row1 + r), (col1 + c)) = num THEN checkBox = 0NEXT c, rEND 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 12GOSUB makebgDIM SHARED pDO    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)SYSTEMboard:PCOPY 1, 0xprint = 0yprint = 0DO    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 DOLOOPRETURNmakebg:FOR drawx = 176 TO 464 STEP 32    PSET (drawx, 96), 7    DRAW "D289"NEXT drawxFOR drawy = 96 TO 384 STEP 32    PSET (176, drawy), 7    DRAW "R289"NEXT drawyFOR darken1x = 175 TO 463 STEP 96    PSET (darken1x, 96), 7    DRAW "D288"NEXT darken1xFOR darken2x = 177 TO 465 STEP 96    PSET (darken2x, 96), 7    DRAW "D288"NEXT darken2xFOR darken1y = 95 TO 383 STEP 96    PSET (176, darken1y), 7    DRAW "R288"NEXT darken1yFOR darken2y = 97 TO 385 STEP 96    PSET (176, darken2y), 7    DRAW "R288"NEXT darken2yPCOPY 0, 1RETURNFUNCTION checkRow (row, num)checkRow = -1FOR col = 1 TO 9    IF puzzle(row, col) = num THEN checkRow = 0NEXT colEND FUNCTIONFUNCTION checkCol (col, num)checkCol = -1FOR row = 1 TO 9    IF puzzle(row, col) = num THEN checkCol = 0NEXT rowEND FUNCTIONFUNCTION checkBox (row, col, num)checkBox = -1rowx = INT((row / 3)) * 3colx = INT((col / 3)) * 3FOR r = 1 TO 3    FOR c = 1 TO 3        IF puzzle((rowx + r), (colx + c)) = num THEN checkBox = 0NEXT c, rEND FUNCTIONFUNCTION solve (row, col)solve = -1IF row > 9 THEN EXIT FUNCTIONIF puzzle(row, col) > 0 THEN    IF col < 9 THEN        puzzle = solve(row, (col + 1))    ELSE        puzzle = solve((row + 1), 1)    END IFELSE    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 = 0END IFEND 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 12GOSUB makebgDIM SHARED xsector, ysectorDO    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)SYSTEMmakebg:FOR drawx = 176 TO 464 STEP 32    PSET (drawx, 96), 7    DRAW "D289"NEXT drawxFOR drawy = 96 TO 384 STEP 32    PSET (176, drawy), 7    DRAW "R289"NEXT drawyFOR darken1x = 175 TO 463 STEP 96    PSET (darken1x, 96), 7    DRAW "D288"NEXT darken1xFOR darken2x = 177 TO 465 STEP 96    PSET (darken2x, 96), 7    DRAW "D288"NEXT darken2xFOR darken1y = 95 TO 383 STEP 96    PSET (176, darken1y), 7    DRAW "R288"NEXT darken1yFOR darken2y = 97 TO 385 STEP 96    PSET (176, darken2y), 7    DRAW "R288"NEXT darken2yPCOPY 0, 1RETURNSUB boardPCOPY 1, 0xprint = 0yprint = 0DO    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 DOLOOPEND SUBFUNCTION checkRow (row, num)checkRow = -1FOR colx = 1 TO 9    IF puzzle(row, colx) = num THEN checkRow = 0NEXT colxEND FUNCTIONFUNCTION checkCol (col, num)checkCol = -1FOR rowx = 1 TO 9    IF puzzle(rowx, col) = num THEN checkCol = 0NEXT rowxEND FUNCTIONFUNCTION checkBox (row, col, num)checkBox = -1rowx = INT(((row - 1) / 3)) * 3colx = INT(((col - 1) / 3)) * 3FOR 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 IFNEXT c, rEND FUNCTIONFUNCTION solve (row, col)solve = -1IF row > 9 THEN EXIT FUNCTIONIF puzzle(row, col) > 0 THEN    IF col < 9 THEN        puzzle = solve(row, (col + 1))    ELSE        puzzle = solve((row + 1), 1)    END IFELSE    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 = 0END IFEND 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 12GOSUB makebgDIM SHARED xsector, ysectorDO    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)SYSTEMmakebg:FOR drawx = 176 TO 464 STEP 32    PSET (drawx, 96), 7    DRAW "D289"NEXT drawxFOR drawy = 96 TO 384 STEP 32    PSET (176, drawy), 7    DRAW "R289"NEXT drawyFOR darken1x = 175 TO 463 STEP 96    PSET (darken1x, 96), 7    DRAW "D288"NEXT darken1xFOR darken2x = 177 TO 465 STEP 96    PSET (darken2x, 96), 7    DRAW "D288"NEXT darken2xFOR darken1y = 95 TO 383 STEP 96    PSET (176, darken1y), 7    DRAW "R288"NEXT darken1yFOR darken2y = 97 TO 385 STEP 96    PSET (176, darken2y), 7    DRAW "R288"NEXT darken2yPCOPY 0, 1RETURNSUB boardPCOPY 1, 0xprint = 0yprint = 0DO    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 DOLOOPEND SUBFUNCTION checkRow (row, num)checkRow = -1FOR colx = 1 TO 9    IF puzzle(row, colx) = num THEN checkRow = 0NEXT colxEND FUNCTIONFUNCTION checkCol (col, num)checkCol = -1FOR rowx = 1 TO 9    IF puzzle(rowx, col) = num THEN checkCol = 0NEXT rowxEND FUNCTIONFUNCTION checkBox (row, col, num)checkBox = -1rowx = INT(((row - 1) / 3)) * 3colx = INT(((col - 1) / 3)) * 3FOR r = 1 TO 3    FOR c = 1 TO 3        IF puzzle((rowx + r), (colx + c)) = num THEN checkBox = 0NEXT c, rEND FUNCTIONFUNCTION solve (row, col)solve = -1IF row > 9 THEN EXIT FUNCTIONIF puzzle(row, col) > 0 THEN    IF col < 9 THEN        puzzle = solve(row, (col + 1))    ELSE        puzzle = solve((row + 1), 1)    END IFELSE    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 = 0END IFEND 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 12GOSUB makebgDO    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)SYSTEMmakebg:FOR drawx = 176 TO 464 STEP 32    PSET (drawx, 96), 7    DRAW "D289"NEXT drawxFOR drawy = 96 TO 384 STEP 32    PSET (176, drawy), 7    DRAW "R289"NEXT drawyFOR darken1x = 175 TO 463 STEP 96    PSET (darken1x, 96), 7    DRAW "D288"NEXT darken1xFOR darken2x = 177 TO 465 STEP 96    PSET (darken2x, 96), 7    DRAW "D288"NEXT darken2xFOR darken1y = 95 TO 383 STEP 96    PSET (176, darken1y), 7    DRAW "R288"NEXT darken1yFOR darken2y = 97 TO 385 STEP 96    PSET (176, darken2y), 7    DRAW "R288"NEXT darken2yPCOPY 0, 1RETURNboard:PCOPY 1, 0xprint = 0yprint = 0DO    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 DOLOOPRETURNFUNCTION checkRow (row, num)checkRow = -1FOR colx = 1 TO 9    IF puzzle(row, colx) = num THEN checkRow = 0NEXT colxEND FUNCTIONFUNCTION checkCol (col, num)checkCol = -1FOR rowx = 1 TO 9    IF puzzle(rowx, col) = num THEN checkCol = 0NEXT rowxEND FUNCTIONFUNCTION checkBox (row, col, num)checkBox = -1rowx = INT(((row - 1) / 3)) * 3colx = INT(((col - 1) / 3)) * 3FOR r = 1 TO 3    FOR c = 1 TO 3        IF puzzle((rowx + r), (colx + c)) = num THEN checkBox = 0NEXT c, rEND FUNCTIONFUNCTION solve (row, col)solve = -1finflag = rowIF finflag > 9 THEN EXIT FUNCTIONIF 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 FUNCTIONELSE    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 = 0END IFEND FUNCTION`
example easy puzzle
Code: [Select]
`puzzle(1, 1) = 0puzzle(1, 2) = 0puzzle(1, 3) = 0puzzle(1, 4) = 4puzzle(1, 5) = 0puzzle(1, 6) = 9puzzle(1, 7) = 0puzzle(1, 8) = 0puzzle(1, 9) = 0puzzle(2, 1) = 2puzzle(2, 2) = 8puzzle(2, 3) = 7puzzle(2, 4) = 0puzzle(2, 5) = 0puzzle(2, 6) = 5puzzle(2, 7) = 6puzzle(2, 8) = 0puzzle(2, 9) = 4puzzle(3, 1) = 0puzzle(3, 2) = 0puzzle(3, 3) = 0puzzle(3, 4) = 8puzzle(3, 5) = 6puzzle(3, 6) = 0puzzle(3, 7) = 3puzzle(3, 8) = 0puzzle(3, 9) = 2puzzle(4, 1) = 0puzzle(4, 2) = 7puzzle(4, 3) = 0puzzle(4, 4) = 3puzzle(4, 5) = 0puzzle(4, 6) = 6puzzle(4, 7) = 0puzzle(4, 8) = 4puzzle(4, 9) = 0puzzle(5, 1) = 0puzzle(5, 2) = 3puzzle(5, 3) = 9puzzle(5, 4) = 0puzzle(5, 5) = 0puzzle(5, 6) = 0puzzle(5, 7) = 8puzzle(5, 8) = 6puzzle(5, 9) = 0puzzle(6, 1) = 0puzzle(6, 2) = 6puzzle(6, 3) = 0puzzle(6, 4) = 9puzzle(6, 5) = 0puzzle(6, 6) = 8puzzle(6, 7) = 0puzzle(6, 8) = 1puzzle(6, 9) = 0puzzle(7, 1) = 4puzzle(7, 2) = 0puzzle(7, 3) = 5puzzle(7, 4) = 0puzzle(7, 5) = 8puzzle(7, 6) = 1puzzle(7, 7) = 0puzzle(7, 8) = 0puzzle(7, 9) = 0puzzle(8, 1) = 6puzzle(8, 2) = 0puzzle(8, 3) = 3puzzle(8, 4) = 2puzzle(8, 5) = 0puzzle(8, 6) = 0puzzle(8, 7) = 7puzzle(8, 8) = 8puzzle(8, 9) = 1puzzle(9, 1) = 0puzzle(9, 2) = 0puzzle(9, 3) = 0puzzle(9, 4) = 6puzzle(9, 5) = 0puzzle(9, 6) = 3puzzle(9, 7) = 0puzzle(9, 8) = 0puzzle(9, 9) = 0`
example hard puzzle
Code: [Select]
`puzzle(1, 1) = 9puzzle(1, 2) = 0puzzle(1, 3) = 0puzzle(1, 4) = 0puzzle(1, 5) = 5puzzle(1, 6) = 0puzzle(1, 7) = 0puzzle(1, 8) = 0puzzle(1, 9) = 0puzzle(2, 1) = 0puzzle(2, 2) = 5puzzle(2, 3) = 0puzzle(2, 4) = 0puzzle(2, 5) = 0puzzle(2, 6) = 0puzzle(2, 7) = 0puzzle(2, 8) = 1puzzle(2, 9) = 4puzzle(3, 1) = 0puzzle(3, 2) = 4puzzle(3, 3) = 8puzzle(3, 4) = 0puzzle(3, 5) = 0puzzle(3, 6) = 1puzzle(3, 7) = 2puzzle(3, 8) = 0puzzle(3, 9) = 0puzzle(4, 1) = 0puzzle(4, 2) = 0puzzle(4, 3) = 2puzzle(4, 4) = 0puzzle(4, 5) = 4puzzle(4, 6) = 3puzzle(4, 7) = 0puzzle(4, 8) = 0puzzle(4, 9) = 0puzzle(5, 1) = 0puzzle(5, 2) = 8puzzle(5, 3) = 9puzzle(5, 4) = 0puzzle(5, 5) = 0puzzle(5, 6) = 0puzzle(5, 7) = 6puzzle(5, 8) = 4puzzle(5, 9) = 0puzzle(6, 1) = 0puzzle(6, 2) = 0puzzle(6, 3) = 0puzzle(6, 4) = 0puzzle(6, 5) = 9puzzle(6, 6) = 0puzzle(6, 7) = 1puzzle(6, 8) = 0puzzle(6, 9) = 0puzzle(7, 1) = 0puzzle(7, 2) = 0puzzle(7, 3) = 3puzzle(7, 4) = 7puzzle(7, 5) = 0puzzle(7, 6) = 0puzzle(7, 7) = 8puzzle(7, 8) = 9puzzle(7, 9) = 0puzzle(8, 1) = 2puzzle(8, 2) = 6puzzle(8, 3) = 0puzzle(8, 4) = 0puzzle(8, 5) = 0puzzle(8, 6) = 0puzzle(8, 7) = 0puzzle(8, 8) = 3puzzle(8, 9) = 0puzzle(9, 1) = 0puzzle(9, 2) = 0puzzle(9, 3) = 0puzzle(9, 4) = 0puzzle(9, 5) = 3puzzle(9, 6) = 0puzzle(9, 7) = 0puzzle(9, 8) = 0puzzle(9, 9) = 2`
« Last Edit: February 21, 2013, 06:07:28 PM by Gorlock »