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 Search this Thread Display Modes
  #211 (permalink)  
Old 10-20-11, 12:42
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Exclamation You don't need to go on page 7 now

--- The query you have to execute if you want to change table ---
Code:
drop table Sd_Source;
--- Execute this one time, and if you want create (or recreate) the table Sd_Source ---
--- 1.

Code:
create table Sd_Source 
(sd_id    integer    not null,
 sd_Lnum  integer    not null,
 sd_SLine Varchar(9) not null, 
 get_id  integer,
 ins_tms timestamp not null with default);
--- 2.
Code:
CREATE UNIQUE INDEX IX_Source 
ON Sd_Source (sd_id ASC, sd_Lnum asc) CLUSTER;
--- Don't need to do this if you don't need to drop the view: ---
Code:
drop view SDVW_SOLUTION;
--- You have to create view SDVW_Solution (after drop, or in the very first time):
(don't worry if you'll get the warning message): --- (FULL QUERY in the attachment)


Code:
create view SDVW_Solution 
(Sudoku_Solution, Source_id, Source_line) as
with.... (the full code get from attachment).... 
These operations are required any time when you add the new Sudoku which you want to solve:

Any time when you have added the new sudoku puzzle to the Sd_Source table
you would use the following query, or any other query which you want use
for Insert the input values into Sd_Source table
(Where 0 - unknown cell, digits 1 - 9 -- input key) :

Code:
select max(sd_id) from final table
(insert into Sd_Source  
select ifnull(max(sd_id), 0) + 1, 1, '080100920' 
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())       
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 2, '000005000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 3, '024000380'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all 
select ifnull(max(sd_id), 0) + 1, 4, '091003000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 5, '060000040'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 6, '000800290'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 7, '035000760'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 8, '000500000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 9, '079006010'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
);
After you finish all required operations you have to run this simple query:
Code:
select sudoku_solution from SDVW_SOLUTION
Finally you'll get the Result:
Quote:
Line 1: | 7 | 8 | 6 | 1 | 3 | 4 | 9 | 2 | 5 |
Line 2: | 9 | 1 | 3 | 2 | 8 | 5 | 4 | 7 | 6 |
Line 3: | 5 | 2 | 4 | 6 | 7 | 9 | 3 | 8 | 1 |
Line 4: | 2 | 9 | 1 | 7 | 4 | 3 | 6 | 5 | 8 |
Line 5: | 3 | 6 | 8 | 9 | 5 | 2 | 1 | 4 | 7 |
Line 6: | 4 | 5 | 7 | 8 | 6 | 1 | 2 | 9 | 3 |
Line 7: | 1 | 3 | 5 | 4 | 9 | 8 | 7 | 6 | 2 |
Line 8: | 6 | 4 | 2 | 5 | 1 | 7 | 8 | 3 | 9 |
Line 9: | 8 | 7 | 9 | 3 | 2 | 6 | 5 | 1 | 4 |
Lenny
Attached Files
File Type: txt Sudoku_Solution_By_View.txt (26.0 KB, 2 views)

Last edited by Lenny77; 10-20-11 at 18:05.
Reply With Quote
  #212 (permalink)  
Old 11-04-11, 17:33
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Regard my best wishes to Lenny (same name but not me).
He changed his job from UBS to....


Also, maybe somebody knows what is Ken-ken ?

Lenny
Reply With Quote
  #213 (permalink)  
Old 11-10-11, 10:58
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
It is so difficult to find good algorithm to Ken-ken.

Doesn’t matter 4 x 4, or 6 x 6 we have additionally the operations which we don’t have in Sudoku....

Lenny
Reply With Quote
  #214 (permalink)  
Old 12-06-11, 12:49
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
People, where are you ?
Reply With Quote
  #215 (permalink)  
Old 12-09-11, 10:45
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Wink Friday Sudoku

....You can find out "HOW" on this page....
Any time when you add the new sudoku puzzle to the Sd_Source table
you have to use following query, or any query which
you want to use for insert start numbers of your Sudoku puzzle.
After insertion into the table performed, you can run
select sudoku_solution from SDVW_SOLUTION view.
*/

Code:
select max(sd_id) from final table
(insert into Sd_Source  
select ifnull(max(sd_id), 0) + 1, 1, '002001400'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())       
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 2, '040963108'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 3, '000008003'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all 
select ifnull(max(sd_id), 0) + 1, 4, '000600004'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 5, '090000080'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 6, '300009000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 7, '100000000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 8, '008092050'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 9, '006300700'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
);

select sudoku_solution from SDVW_SOLUTION;
Result:
Line 1: | 8 | 3 | 2 | 5 | 7 | 1 | 4 | 6 | 9 |
Line 2: | 5 | 4 | 7 | 9 | 6 | 3 | 1 | 2 | 8 |
Line 3: | 6 | 1 | 9 | 4 | 2 | 8 | 5 | 7 | 3 |
Line 4: | 2 | 8 | 5 | 6 | 1 | 7 | 9 | 3 | 4 |
Line 5: | 7 | 9 | 1 | 2 | 3 | 4 | 6 | 8 | 5 |
Line 6: | 3 | 6 | 4 | 8 | 5 | 9 | 2 | 1 | 7 |
Line 7: | 1 | 5 | 3 | 7 | 4 | 6 | 8 | 9 | 2 |
Line 8: | 4 | 7 | 8 | 1 | 9 | 2 | 3 | 5 | 6 |
Line 9: | 9 | 2 | 6 | 3 | 8 | 5 | 7 | 4 | 1 |

Lenny
Reply With Quote
  #216 (permalink)  
Old 02-03-12, 17:58
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Arrow New Sudoku (16 x 16)

I believe the new sudoku (with same rules as for 9 x 9) could be interesting for many.

This is an example of solved 16 x 16 Sudoku, or shortly Sudoku16:

Code:
1234 5678 9abc defg
5678 1234 defg 9abc
9abc defg 5678 1234
defg 9abc 1234 5678
 
2345 6789 abcd efg1
6789 2345 efg1 abcd
abcd 6789 2345 efg1
efg1 abcd 6789 2345
 
3456 789a bcde fg12
789a 3456 fg12 bcde
fg12 bcde 789a 3456
bcde fg12 3456 789a
 
4567 89ab cdef g123
89ab 4567 g123 cdef
g123 cdef 89ab 4567
cdef g123 4567 89ab
Yes, there is the NEXT level of difficulty.

Lenny
Reply With Quote
  #217 (permalink)  
Old 04-05-12, 17:03
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Wink Sudoku Puzzle (solved by query)

One more Sudoku puzzle in your collection:

Code:
select max(sd_id) from final table
(insert into Sd_Source  
select ifnull(max(sd_id), 0) + 1, 1, '801005000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())       
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 2, '904000000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 3, '050000030'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all 
select ifnull(max(sd_id), 0) + 1, 4, '040020016'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 5, '300546002'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 6, '260090040'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 7, '020000060'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 8, '000000305'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 9, '000700900'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
);

select sudoku_solution from SDVW_SOLUTION;

Result:

Quote:
Line 1: | 8 | 3 | 1 | 4 | 6 | 5 | 2 | 7 | 9 |
Line 2: | 9 | 7 | 4 | 2 | 3 | 1 | 6 | 5 | 8 |
Line 3: | 6 | 5 | 2 | 8 | 7 | 9 | 4 | 3 | 1 |
Line 4: | 7 | 4 | 9 | 3 | 2 | 8 | 5 | 1 | 6 |
Line 5: | 3 | 1 | 8 | 5 | 4 | 6 | 7 | 9 | 2 |
Line 6: | 2 | 6 | 5 | 1 | 9 | 7 | 8 | 4 | 3 |
Line 7: | 5 | 2 | 3 | 9 | 8 | 4 | 1 | 6 | 7 |
Line 8: | 4 | 9 | 7 | 6 | 1 | 2 | 3 | 8 | 5 |
Line 9: | 1 | 8 | 6 | 7 | 5 | 3 | 9 | 2 | 4 |
Lenny
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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