| |
|
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.
|
 |
|

06-29-12, 12:51
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
Sudoku Solver for Mainframe users
|
|
Same rules as for Windows users:
One query solve any level of Sudoku in seconds.
The query is ready to run in SPUFI, or another Mainframe applications.
================================================== ==
1. Fill up the Source table, where "0" for unknown cells of Sudoku.
Quote:
Source (line, sudoku_str) as
(
select 1, '041705098'
from sysibm.sysdummy1
union all
select 2, '050308000'
from sysibm.sysdummy1
union all
select 3, '000040000'
from sysibm.sysdummy1
union all
select 4, '205000031'
from sysibm.sysdummy1
union all
select 5, '900000005'
from sysibm.sysdummy1
union all
select 6, '170000802'
from sysibm.sysdummy1
union all
select 7, '000030000'
from sysibm.sysdummy1
union all
select 8, '000107020'
from sysibm.sysdummy1
union all
select 9, '410602750'
from sysibm.sysdummy1
)
|
2. After you finish with Source table, Run the query
3. All you can find in the attachment.
================================================== ==
Thanks. Lenny
|
Last edited by Lenny77; 06-29-12 at 13:01.
|

06-29-12, 15:03
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
Hello DB2 Forum
Hi Michael and Eugene.
Join me on DB2 Forum !
Lenny
|
|

06-29-12, 23:12
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
This Solver is working in Windows as well as Mainframe
|
|
Yes. This Solver is working everywhere.
I just changed the width of the line because the mainframe line width
not exceeding 80 characters.
Lenny
|
|

07-03-12, 16:51
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
HAPPY GURU PURNIMA for ALL of you and Independent Day, too !
Lenny
|
|

07-05-12, 15:10
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
About stopper and how they are improve performance
I found somewhere this very high level Sudoku:
Code:
Source (line, sudoku_str) as
(
select 1, '800000000'
from sysibm.sysdummy1
union all
select 2, '003600000'
from sysibm.sysdummy1
union all
select 3, '070090200'
from sysibm.sysdummy1
union all
select 4, '050007000'
from sysibm.sysdummy1
union all
select 5, '000045700'
from sysibm.sysdummy1
union all
select 6, '000100030'
from sysibm.sysdummy1
union all
select 7, '001000068'
from sysibm.sysdummy1
union all
select 8, '008500010'
from sysibm.sysdummy1
union all
select 9, '090000400'
from sysibm.sysdummy1
)
The result
Quote:
Sudoku Solution
Line 1: | 8 | 1 | 2 | 7 | 5 | 3 | 6 | 4 | 9 |
Line 2: | 9 | 4 | 3 | 6 | 8 | 2 | 1 | 7 | 5 |
Line 3: | 6 | 7 | 5 | 4 | 9 | 1 | 2 | 8 | 3 |
Line 4: | 1 | 5 | 4 | 2 | 3 | 7 | 8 | 9 | 6 |
Line 5: | 3 | 6 | 9 | 8 | 4 | 5 | 7 | 2 | 1 |
Line 6: | 2 | 8 | 7 | 1 | 6 | 9 | 5 | 3 | 4 |
Line 7: | 5 | 2 | 1 | 9 | 7 | 4 | 3 | 6 | 8 |
Line 8: | 4 | 3 | 8 | 5 | 2 | 6 | 9 | 1 | 7 |
Line 9: | 7 | 9 | 6 | 3 | 1 | 8 | 4 | 5 | 2 |
|
I have got spending more than 4 minutes (!).
I was shocked, because usually Solver spend the seconds.
I guess what really happened.
The Solver does not stop after it found the first solved Sudoku.
I found the easiest solution of the problem:
We have to add only one short sentence to our solver, which will stop execution on the first found solution.
This sentence is "Fetch First Row Only".
We have to put it in the right place, that it.
Code:
with
Source (line, sudoku_str) as
(
select 1, '800000000'
from sysibm.sysdummy1
....
....
....
) SL9
Fetch First Row Only ) ii
)
select line_1 "Sudoku Solution"
from sud_solution_tbl
....
....
....
union all
select line_9 "Sudoku Solution" from sud_solution_tbl
;
Now we got the solution for this very hard Sudoku in 3 seconds.
Lenny
|
Last edited by Lenny77; 07-05-12 at 15:33.
|

07-07-12, 08:57
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
I am going on Vacation in Scandinavia which has never been before.
See all of you after 2 weeks.
! Bye-Bye !
Yours Lenny
|
Last edited by Lenny77; 07-07-12 at 09:09.
|

07-21-12, 07:05
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
Vacation in Scandinavia was great !
Now back to reality.
Lenny
|
|

07-27-12, 15:52
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
The reality also is not so bad. In NY hot and humid now. Yesterday the small hurricane was happened.
Lenny
|
|

08-14-12, 14:51
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
Just one more solved by DB2 Sudoku
Level-4 Sudoku, solved in 1 second.
Code:
Source (line, sudoku_str) as
(
select 1, '072000000'
from sysibm.sysdummy1
union all
select 2, '100680090'
from sysibm.sysdummy1
union all
select 3, '003004000'
from sysibm.sysdummy1
union all
select 4, '010093080'
from sysibm.sysdummy1
union all
select 5, '300000007'
from sysibm.sysdummy1
union all
select 6, '054700010'
from sysibm.sysdummy1
union all
select 7, '000400600'
from sysibm.sysdummy1
union all
select 8, '030005041'
from sysibm.sysdummy1
union all
select 9, '000000870'
from sysibm.sysdummy1
)
Quote:
Line 1: | 8 | 7 | 2 | 3 | 5 | 9 | 1 | 6 | 4 |
Line 2: | 1 | 4 | 5 | 6 | 8 | 7 | 3 | 9 | 2 |
Line 3: | 9 | 6 | 3 | 2 | 1 | 4 | 7 | 5 | 8 |
Line 4: | 2 | 1 | 7 | 5 | 9 | 3 | 4 | 8 | 6 |
Line 5: | 3 | 9 | 8 | 1 | 4 | 6 | 5 | 2 | 7 |
Line 6: | 6 | 5 | 4 | 7 | 2 | 8 | 9 | 1 | 3 |
Line 7: | 5 | 8 | 1 | 4 | 7 | 2 | 6 | 3 | 9 |
Line 8: | 7 | 3 | 9 | 8 | 6 | 5 | 2 | 4 | 1 |
Line 9: | 4 | 2 | 6 | 9 | 3 | 1 | 8 | 7 | 5 |
|
Lenny
|
|

08-30-12, 11:57
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
It's not a lot of people can understand how it works.
Feel free to ask me questions about.
Lenny
|
|

09-20-12, 12:44
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
One more Sudoku for Sudoku fans
Code:
Source (line, sudoku_str) as
(
select 1, '007052609'
from sysibm.sysdummy1
union all
select 2, '006000300'
from sysibm.sysdummy1
union all
select 3, '000800001'
from sysibm.sysdummy1
union all
select 4, '400180003'
from sysibm.sysdummy1
union all
select 5, '000000000'
from sysibm.sysdummy1
union all
select 6, '700039005'
from sysibm.sysdummy1
union all
select 7, '800005000'
from sysibm.sysdummy1
union all
select 8, '004000800'
from sysibm.sysdummy1
union all
select 9, '503690100'
from sysibm.sysdummy1
)
The Result:
Quote:
Line 1: | 1 | 8 | 7 | 3 | 5 | 2 | 6 | 4 | 9 |
Line 2: | 2 | 5 | 6 | 9 | 4 | 1 | 3 | 8 | 7 |
Line 3: | 3 | 4 | 9 | 8 | 7 | 6 | 5 | 2 | 1 |
Line 4: | 4 | 6 | 5 | 1 | 8 | 7 | 2 | 9 | 3 |
Line 5: | 9 | 3 | 2 | 5 | 6 | 4 | 7 | 1 | 8 |
Line 6: | 7 | 1 | 8 | 2 | 3 | 9 | 4 | 6 | 5 |
Line 7: | 8 | 7 | 1 | 4 | 2 | 5 | 9 | 3 | 6 |
Line 8: | 6 | 9 | 4 | 7 | 1 | 3 | 8 | 5 | 2 |
Line 9: | 5 | 2 | 3 | 6 | 9 | 8 | 1 | 7 | 4 |
|
Lenny
|
|

10-16-12, 17:25
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
Test
Try to solve this Sudoku manually, then run my Solver and compare the solutions:
Code:
Source (line, sudoku_str) as
(
select 1, '003509040'
from sysibm.sysdummy1
union all
select 2, '000700006'
from sysibm.sysdummy1
union all
select 3, '080000010'
from sysibm.sysdummy1
union all
select 4, '008907051'
from sysibm.sysdummy1
union all
select 5, '206050809'
from sysibm.sysdummy1
union all
select 6, '950608400'
from sysibm.sysdummy1
union all
select 7, '060000090'
from sysibm.sysdummy1
union all
select 8, '800004000'
from sysibm.sysdummy1
union all
select 9, '020105700'
from sysibm.sysdummy1
)
Solution:
Quote:
Line 1: | 6 | 1 | 3 | 5 | 8 | 9 | 2 | 4 | 7 |
Line 2: | 5 | 4 | 2 | 7 | 1 | 3 | 9 | 8 | 6 |
Line 3: | 7 | 8 | 9 | 2 | 4 | 6 | 5 | 1 | 3 |
Line 4: | 4 | 3 | 8 | 9 | 2 | 7 | 6 | 5 | 1 |
Line 5: | 2 | 7 | 6 | 4 | 5 | 1 | 8 | 3 | 9 |
Line 6: | 9 | 5 | 1 | 6 | 3 | 8 | 4 | 7 | 2 |
Line 7: | 1 | 6 | 5 | 8 | 7 | 2 | 3 | 9 | 4 |
Line 8: | 8 | 9 | 7 | 3 | 6 | 4 | 1 | 2 | 5 |
Line 9: | 3 | 2 | 4 | 1 | 9 | 5 | 7 | 6 | 8 |
|
Thanks. Lenny
|
|

10-22-12, 13:20
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
Hi Vishal ! It always nice to talk with you !
Lenny 
|
|

11-12-12, 12:01
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 958
|
|
Congratulation with Great Indian Holiday !
Lenny
|
|

11-12-12, 17:34
|
|
∞∞∞∞∞∞
|
|
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 2,180
|
|
Quote:
Originally Posted by Lenny77
Hi Michael and Eugene
|
Quote:
Originally Posted by Lenny77
Hi Vishal
|
Are you talking to yourself...
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|