# Thread: Absolute SUDOKU Solver

1. Registered User
Join Date
Jul 2009
Location
NY
Posts
963

## Unanswered: Absolute SUDOKU Solver

I want present to you Sudoku Solver, created by me today, which find solution for any level of Sudoku in very short time from 20 to 300 seconds,
depends on difficulty level.

This solution prevents from infinite loop. So if solution exists it'll be found.

In this example I used the very hard sudoku and got solution in 2 minutes.

Sudoku Line

XXX7X29X4
4X1X687XX
XXXXXXXX8
6X7XX142X
XXXXXXXXX
X236XX1X5
1XXXXXXXX
XX827X5X1
7X24X6XXX

Line 1: | 8 | 6 | 5 | 7 | 3 | 2 | 9 | 1 | 4 |
Line 2: | 4 | 3 | 1 | 9 | 6 | 8 | 7 | 5 | 2 |
Line 3: | 2 | 7 | 9 | 1 | 4 | 5 | 6 | 3 | 8 |
Line 4: | 6 | 8 | 7 | 5 | 9 | 1 | 4 | 2 | 3 |
Line 5: | 5 | 1 | 4 | 3 | 2 | 7 | 8 | 9 | 6 |
Line 6: | 9 | 2 | 3 | 6 | 8 | 4 | 1 | 7 | 5 |
Line 7: | 1 | 9 | 6 | 8 | 5 | 3 | 2 | 4 | 7 |
Line 8: | 3 | 4 | 8 | 2 | 7 | 9 | 5 | 6 | 1 |
Line 9: | 7 | 5 | 2 | 4 | 1 | 6 | 3 | 8 | 9 |

==> Code in attachment. <==

Thanks everybody (Especially tonkuma) who shown to me drawbacks in the Old Solver.

Leonid Khiger

2. Registered User
Join Date
Feb 2009
Posts
114
this is great! spasibo Leonid! can you do the same for chess? a chess-solver?

3. Registered User
Join Date
Jul 2009
Location
NY
Posts
963
Originally Posted by db2dummy1
this is great! spasibo Leonid! can you do the same for chess? a chess-solver?
Had father 3 sons, 2 and dummy1 !

I have made something for chess, already.
But now chess-sql works only as chess-puzzles solver.

Yours Lenny

4. Registered User
Join Date
Jul 2009
Location
NY
Posts
963

## Absolute SUDOKU Solver V2 optimized

Sorry guys, but I can't stop.

Now I have optimized Absolute SUDOKU Solver and found solution for same puzzle which I shown to you yesterday in 20 seconds.

Compare to 2 minutes with V1 of ASS this is not so bad, I think.

Lenny

5. Registered User
Join Date
Jul 2009
Location
NY
Posts
963
You can try yourself, trying to solve Valentine Sudoku:

x59xxx38x
2xx9x1xx6
8xxx7xxx2
9xxxxxxx3
1xxxxxxx5
x2xxxxx7x
xx1xxx8xx
xxx5x6xxx
xxxx2xxxx
Then we'll compare result and time.

Lenny

6. Registered User
Join Date
Jul 2009
Location
NY
Posts
963

## Final Solution (SUDOKU Killer)

I want present to Final Solution (SUDOKU Killer).

This one working 60 time faster then Version Two.

Lenny

7. Registered User
Join Date
Jul 2009
Location
NY
Posts
963

## Sudoku Killer for Multy Solutions

There is level 3 sudoku, having 2 empty lines:

Sudoku Line

XXXXXXXXX
X7XXX6X3X
X3X72XX4X
7XXXX8XX1
6XX3X7XX5
5X91XXXXX
X8XX91X2X
X916XXX7X
XXXXXXXXX
Line 1: | 9 | 6 | 2 | 8 | 3 | 4 | 1 | 5 | 7 |
Line 2: | 8 | 7 | 4 | 5 | 1 | 6 | 9 | 3 | 2 |
Line 3: | 1 | 3 | 5 | 7 | 2 | 9 | 6 | 4 | 8 |
Line 4: | 7 | 2 | 3 | 9 | 5 | 8 | 4 | 6 | 1 |
Line 5: | 6 | 1 | 8 | 3 | 4 | 7 | 2 | 9 | 5 |
Line 6: | 5 | 4 | 9 | 1 | 6 | 2 | 7 | 8 | 3 |
Line 7: | 3 | 8 | 7 | 4 | 9 | 1 | 5 | 2 | 6 |
Line 8: | 2 | 9 | 1 | 6 | 8 | 5 | 3 | 7 | 4 |
Line 9: | 4 | 5 | 6 | 2 | 7 | 3 | 8 | 1 | 9 |

Our solver spent 11 second to find this single solution.

Now we make simple experiment: we'll change line 4 by remove 1 from source string:

7XXXX8XX1 ==> 7XXXX8XX0

We expect the same single solution, but not.

Because we have 2 empty lines we'll have multiple solutions.

Ok, every solution will shown to you, but how ?

Line 1: ........
Line 1: ........
..................
Line 1: ........
Line 2: ........
Line 2: ........
..................
Line 2: ........ etc.

How combine these lines in complete sudoku solutions ?

For this I created the new termin (column) named Weight.

The weight has to be unique for every single solution.

Weight = 'Line 1:... ' || 'Line 2:... ' ||.... || 'Line 9:... '.

Then I used Group By and Order BY for Weight & Line##.

As Result:

Sudoku Line
XXXXXXXXX
X7XXX6X3X
X3X72XX4X
7XXXX8XXX
6XX3X7XX5
5X91XXXXX
X8XX91X2X
X916XXX7X
XXXXXXXXX
Line 1: | 1 | 6 | 2 | 8 | 3 | 4 | 7 | 5 | 9 |
Line 2: | 9 | 7 | 4 | 5 | 1 | 6 | 8 | 3 | 2 |
Line 3: | 8 | 3 | 5 | 7 | 2 | 9 | 6 | 4 | 1 |
Line 4: | 7 | 1 | 3 | 9 | 5 | 8 | 2 | 6 | 4 |
Line 5: | 6 | 2 | 8 | 3 | 4 | 7 | 1 | 9 | 5 |
Line 6: | 5 | 4 | 9 | 1 | 6 | 2 | 3 | 8 | 7 |
Line 7: | 3 | 8 | 7 | 4 | 9 | 1 | 5 | 2 | 6 |
Line 8: | 2 | 9 | 1 | 6 | 8 | 5 | 4 | 7 | 3 |
Line 9: | 4 | 5 | 6 | 2 | 7 | 3 | 9 | 1 | 8 |

Line 1: | 1 | 6 | 2 | 8 | 3 | 4 | 7 | 5 | 9 |
Line 2: | 9 | 7 | 4 | 5 | 1 | 6 | 8 | 3 | 2 |
Line 3: | 8 | 3 | 5 | 7 | 2 | 9 | 6 | 4 | 1 |
Line 4: | 7 | 1 | 3 | 9 | 5 | 8 | 2 | 6 | 4 |
Line 5: | 6 | 2 | 8 | 3 | 4 | 7 | 9 | 1 | 5 |
Line 6: | 5 | 4 | 9 | 1 | 6 | 2 | 3 | 8 | 7 |
Line 7: | 3 | 8 | 7 | 4 | 9 | 1 | 5 | 2 | 6 |
Line 8: | 2 | 9 | 1 | 6 | 8 | 5 | 4 | 7 | 3 |
Line 9: | 4 | 5 | 6 | 2 | 7 | 3 | 1 | 9 | 8 |

Line 1: | 1 | 6 | 2 | 8 | 3 | 4 | 7 | 5 | 9 |
Line 2: |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| 6 | 4 |
Line 5: | 6 | 1 | 8 | 3 | 4 | 7 | 2 | 9 | 5 |
Line 6: | 5 | 4 | 9 | 1 | 6 | 2 | 3 | 8 | 7 |
Line 7: | 3 | 8 | 7 | 4 | 9 | 1 | 5 | 2 | 6 |
Line 8: | 2 | 9 | 1 | 6 | 8 | 5 | 4 | 7 | 3 |
Line 9: | 4 | 5 | 6 | 2 | 7 | 3 | 8 | 1 | 9 |

we got 8 different solutions in 1 minute.

Lenny

P.S. Code in an attachment

8. ∞∞∞∞∞∞
Join Date
Aug 2008
Location
Posts
2,381
Originally Posted by Lenny77
Had father 3 sons, 2 and dummy1 !

I have made something for chess, already.
But now chess-sql works only as chess-puzzles solver.

Yours Lenny

Leonid, what makes you think dummy1 is one of 3 sons, maybe daughther

9. Registered User
Join Date
Jul 2009
Location
NY
Posts
963
Originally Posted by db2girl
Leonid, what makes you think dummy1 is one of 3 sons, maybe daughther
You are absolutely righ. Could be daughther, could be twins.

This is old russian story about 1 father and 3 sons.

One of them had exactly the same name with dummy1.

Lenny

10. ∞∞∞∞∞∞
Join Date
Aug 2008
Location
Posts
2,381
I remember about 1 father and 3 sons

I'm not expert in English, but I believe dummy is not the same as durak

11. Registered User
Join Date
Jul 2009
Location
NY
Posts
963
Originally Posted by db2girl
I remember about 1 father and 3 sons

I'm not expert in English, but I believe dummy is not the same as durak
I did not say so. But Ivan Durak was smartest guy in russia. Forever.

Dummy1 understood my joke, what about you ?

Lenny

12. ∞∞∞∞∞∞
Join Date
Aug 2008
Location
Posts
2,381
I knew you were referring to that story about father and 3 sons, but maybe I didn't understand your joke.

13. Registered User
Join Date
Jul 2009
Location
NY
Posts
963
Originally Posted by db2girl
I knew you were referring to that story about father and 3 sons, but maybe I didn't understand your joke.
Bella, what do you want from me ?

I don't fill sorry.
He asked me about chess-solver in DB2.
I have answered to him, how I want. That it.

Lenny
Last edited by Lenny77; 09-25-09 at 17:32.

14. ∞∞∞∞∞∞
Join Date
Aug 2008
Location
Posts
2,381
Originally Posted by Lenny77
Bella, what do you want from me ?
I was just joking with you... Sorry for "flooding" your thread, I'll stop here.

15. Registered User
Join Date
Jul 2009
Location
NY
Posts
963
Originally Posted by db2girl
I was just joking with you... Sorry for "flooding" your thread, I'll stop here.
It's Ok. How in Canada translate the word "dummy" to russian ?

Lenny

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•