|
Решение SUDOKU методами DB2 (быстрый ответ)
|
|||
---|---|---|---|
#18+
Я попробовал решить судоку пользуясь чистым ДБ2. Вроде получилось. Можете попробовать как это работает и вы. Итак это одна формула, которая требует версию 8, или выше. Думаю вам будет интересно. Стартуем с исходной головоломки, которую вы теперь можете найти в любой газете, или в книге, или в Инете. Заменяем пропуски в таблице (неизвестные цифры от 1 до 9) цифрой "0". Получаем следующую исходную таблицу (например): 090100000 037020000 060908004 009070000 206000107 000050300 700603050 000080630 000002040 Вводим линии в таблицу SudokuIn (line, sudoku_str) (найдёте в формуле из прикреплённого файла и поймёте как). Запускаем на исполнение, получаем результативную таблицу: | 5 | 9 | 4 | 1 | 6 | 7 | 8 | 2 | 3 | | 8 | 3 | 7 | 4 | 2 | 5 | 9 | 1 | 6 | | 1 | 6 | 2 | 9 | 3 | 8 | 5 | 7 | 4 | | 3 | 8 | 9 | 2 | 7 | 1 | 4 | 6 | 5 | | 2 | 5 | 6 | 3 | 4 | 9 | 1 | 8 | 7 | | 4 | 7 | 1 | 8 | 5 | 6 | 3 | 9 | 2 | | 7 | 4 | 8 | 6 | 1 | 3 | 2 | 5 | 9 | | 9 | 2 | 5 | 7 | 8 | 4 | 6 | 3 | 1 | | 6 | 1 | 3 | 5 | 9 | 2 | 7 | 4 | 8 | Шлите отзывы. С уважением, Леонид Хигер. ... |
|||
:
Нравится:
Не нравится:
|
|||
07.09.2009, 20:07 |
|
Решение SUDOKU методами DB2 (быстрый ответ)
|
|||
---|---|---|---|
#18+
For everybody who loves the simple ideas and strong algorithms I found another way to solve the sudoku puzzles. This algorithm based on the simple idea: If in all lines, columns and regions we have all numbers from 1 to 9 we have also the same summaries of these numbers Sum(i) = Sum(j) = Sum(region) = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45. (marked Sij.S) But this is not enough to solve Sudoku. That's why I used the Sum of the power(2, Aij) = 2^1 + 2^2 +... + 2^8 + 2^9 = 1022.(marked Sij.Y) We created the system of 81 equations and let to DB2 find solution of it. If input was correct - Sudoku solved ! But it's running for 3 to 5 minutes and I continue to work on it to improve performance of the query. If you'll have some ideas how to improve performance I'll appreciate your solution. Thanks, lenny Khiger ... |
|||
:
Нравится:
Не нравится:
|
|||
08.09.2009, 03:44 |
|
Решение SUDOKU методами DB2 (быстрый ответ)
|
|||
---|---|---|---|
#18+
We can change the input table (SudokuIn) to the user created table instead of sysibm.sysdummy1: SudokuIn (line, sudoku_str) as ( select 1, '090100000' from sysibm.sysdummy1 union all select 2, '037020000' from sysibm.sysdummy1 union all ......... union all select 9, '..... ) The structure of table could be any, for example: Sudoku_tbl (sud_id integer not null, sud_line_no integer not null, sud_line varchar(100) not null, sud_oper char(3) ) In this case we have to insert into table before: Insert into Sudoku_tbl select 123, 1, '090100000', 'in' from sysibm.sysdummy1 union all select 123, 2, '037020000', 'in' from sysibm.sysdummy1 union all ......... union all select 123, 9, '....., 'in' from sysibm.sysdummy1 Then we have to change SudokuIn: SudokuIn (line, sudoku_str) as ( select sud_line_no, sud_line from Sudoku_tbl where sud_id = 123 and sud_oper = 'in' ) Finally at the end we have to insert the lines into Sudoku_tbl where we change sud_oper from 'in' to out. Thanks, Lenny ... |
|||
:
Нравится:
Не нравится:
|
|||
09.09.2009, 05:48 |
|
Решение SUDOKU методами DB2 (быстрый ответ)
|
|||
---|---|---|---|
#18+
На днях я завершил работу над кодом, который очень быстро решает любую СУДОКУ. Если кому интересно - дайте знать. Я опубликую здесь. С приветом. Лёня Хигер. ... |
|||
:
Нравится:
Не нравится:
|
|||
24.09.2009, 06:00 |
|
|
start [/forum/topic.php?fid=43&gotonew=1&tid=1600506]: |
0ms |
get settings: |
9ms |
get forum list: |
15ms |
check forum access: |
4ms |
check topic access: |
4ms |
track hit: |
49ms |
get topic data: |
39ms |
get first new msg: |
9ms |
get forum data: |
3ms |
get page messages: |
46ms |
get tp. blocked users: |
2ms |
others: | 241ms |
total: | 421ms |
0 / 0 |