If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Absolute SUDOKU Solver

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-22-09, 18:13
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 816
Exclamation 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
Attached Files
File Type: txt Absolute_SUDOKU_Solver_v1.txt (24.8 KB, 348 views)
Reply With Quote
  #2 (permalink)  
Old 09-23-09, 03:06
db2dummy1 db2dummy1 is offline
Registered User
 
Join Date: Feb 2009
Posts: 114
this is great! spasibo Leonid! can you do the same for chess? a chess-solver?
Reply With Quote
  #3 (permalink)  
Old 09-23-09, 11:19
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 816
Quote:
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
Reply With Quote
  #4 (permalink)  
Old 09-23-09, 12:39
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 816
Arrow 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
Attached Files
File Type: txt Absolute_SUDOKU_Solver_v2_optimized.txt (26.1 KB, 181 views)
Reply With Quote
  #5 (permalink)  
Old 09-23-09, 13:43
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 816
You can try yourself, trying to solve Valentine Sudoku:

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

Lenny
Reply With Quote
  #6 (permalink)  
Old 09-24-09, 11:58
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 816
Exclamation Final Solution (SUDOKU Killer)

I want present to Final Solution (SUDOKU Killer).

This one working 60 time faster then Version Two.

Lenny
Attached Files
File Type: txt Absolute_SUDOKU_Solver_v3_Final.txt (29.1 KB, 201 views)
Reply With Quote
  #7 (permalink)  
Old 09-25-09, 12:03
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 816
Arrow 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 | 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9 | 1 | 6 | 8 | 5 | 3 | 7 | 4 |
Line 9: | 4 | 5 | 6 | 2 | 7 | 3 | 8 | 1 | 9 |


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

Line 1: | 9 | 6 | 2 | 8 | 3 | 4 | 7 | 5 | 1 |
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 | 1 | 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
Attached Files
File Type: txt Absolute_SUDOKU_Solver_v5_Weight.txt (29.4 KB, 204 views)
Reply With Quote
  #8 (permalink)  
Old 09-25-09, 16:10
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,612
Quote:
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
Reply With Quote
  #9 (permalink)  
Old 09-25-09, 16:32
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 816
Quote:
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
Reply With Quote
  #10 (permalink)  
Old 09-25-09, 16:51
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,612
I remember about 1 father and 3 sons

I'm not expert in English, but I believe dummy is not the same as durak
Reply With Quote
  #11 (permalink)  
Old 09-25-09, 16:55
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 816
Quote:
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
Reply With Quote
  #12 (permalink)  
Old 09-25-09, 17:10
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,612
I knew you were referring to that story about father and 3 sons, but maybe I didn't understand your joke.
Reply With Quote
  #13 (permalink)  
Old 09-25-09, 17:25
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 816
Quote:
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.
Reply With Quote
  #14 (permalink)  
Old 09-25-09, 17:34
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,612
Quote:
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.
Reply With Quote
  #15 (permalink)  
Old 09-25-09, 17:40
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 816
Quote:
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On