Перейти к содержимому

Публикации LKhiger

22 публикаций создано LKhiger (учитываются публикации только с 19 апреля 2023)


#84703 MegaSUDOKU killer

Отправлено автор: LKhiger 23 февраля 2011 - 02:17 в IBM DB2

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

select max(sd_id) from final table
(insert into Sd_Source  
select ifnull(max(sd_id), 0) + 1, 1, '007206800'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())       
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 2, '006500010'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 3, '803000000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all 
select ifnull(max(sd_id), 0) + 1, 4, '000060350'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 5, '070000080'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 6, '052000000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 7, '000000703'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 8, '960003100'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 9, '005401900'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
);

select sudoku_solution from SDVW_SOLUTION;


Result:

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


Lenny



#79260 Опыты по Теории Вероятностей

Отправлено автор: LKhiger 27 октября 2010 - 03:14 в IBM DB2

Интересно создать ещё одну функцию RandInt() , которая действует на всём интервале целых чисел:

CREATE FUNCTION RandInt()
RETURNS integer 
LANGUAGE SQL 
CONTAINS SQL 
NO EXTERNAL ACTION 
not DETERMINISTIC 
RETURN RandInt(-2147483648, 2147483647);

Эта функция без аргументов.

Интересно изучить её поведение. Даёт ли она целое близкое к 0 ?



#79165 Опыты по Теории Вероятностей

Отправлено автор: LKhiger 23 октября 2010 - 19:54 в IBM DB2

Dice game / two players / 3 dices

We will use the RandInt(m, n) function, because of dice has numbers (in random sequence)
from 1 to 6, so it will be RandInt(1, 6) for each dice:


Select 
player1.dice1, player1.dice2, player1.dice3, 
player2.dice1, player2.dice2, player2.dice3, 
(player1.dice1 + player1.dice2 + player1.dice3) player1,
(player2.dice1 + player2.dice2 + player2.dice3) player2,
case when (player1.dice1 + player1.dice2 + player1.dice3) >
          (player2.dice1 + player2.dice2 + player2.dice3)
     then 'Player1  WIN !' 
     when (player1.dice1 + player1.dice2 + player1.dice3) <
          (player2.dice1 + player2.dice2 + player2.dice3)
     then 'Player2  WIN !' 
     else 'Tie (draw)' 
end result   
from
(select randint(1, 6) dice1, randint(1, 6) dice2, randint(1, 6) dice3
from sysibm.sysdummy1) player1
,
(select randint(1, 6) dice1, randint(1, 6) dice2, randint(1, 6) dice3
from sysibm.sysdummy1) player2 



#79164 Опыты по Теории Вероятностей

Отправлено автор: LKhiger 23 октября 2010 - 19:36 в IBM DB2

Change RandInt function, override RandInt

The function RandInt(integer) is working now in intervals:
[0, X] when X > 0
[X, 0] when X < 0
[0, 1] when X in (0, 1)

drop function RandInt(integer);

CREATE FUNCTION RandInt (X integer) 
RETURNS integer 
LANGUAGE SQL 
CONTAINS SQL 
NO EXTERNAL ACTION 
not DETERMINISTIC 
RETURN 
case when X = 0 
then int(1 * Rand() + .5)
else int(X * Rand() + 0.5 * sign(X))
end
;

The function RandInt(integer, integer) is overriding RandInt(integer) and
working in intervals:
[start#, end#] when end# >= start#
[end#, start#] when end# <= start#

CREATE FUNCTION RandInt (start# integer, end# integer) 
RETURNS integer 
LANGUAGE SQL 
CONTAINS SQL 
NO EXTERNAL ACTION 
not DETERMINISTIC 
RETURN RandInt(end# - start#) + start#;

What could be also interesting to us:
Create statement of RandInt(integer, integer) function consists call to
parent function RandInt(integer).

Example of using new functions:

select 
randint(500) int1, randint(1000) int2, randint(500, 1000) int3
from sysibm.sysdummy1;



#79131 MegaSUDOKU killer

Отправлено автор: LKhiger 22 октября 2010 - 12:35 в IBM DB2

High Level Sudoku

/* 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
After insert into table, you can select sudoku_solution from SDVW_SOLUTION
*/

select max(sd_id) from final table
(insert into Sd_Source  
select ifnull(max(sd_id), 0) + 1, 1, '700800060'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())       
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 2, '000000001'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 3, '508609000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all 
select ifnull(max(sd_id), 0) + 1, 4, '300700049'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 5, '000000000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 6, '980006003'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 7, '000501906'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 8, '600000000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 9, '170403005'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
);

select sudoku_solution from SDVW_SOLUTION;

Result:

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




#78953 Опыты по Теории Вероятностей

Отправлено автор: LKhiger 19 октября 2010 - 01:50 в IBM DB2

Отличный ответ ! Я тоже так думал изначально. :good:

Но почему тогда весь мир дружно говорит о чуде ? :clapping:

Откуда:

По мнению специалистов, статистическая вероятность такого события составляет 0,00000000000025


И я понял откуда взялось это решение:

Эта вероятность такого события как смешение двух барабанов с одинаковым набором шаров, в одном барабане, и доставания из общего барабана ряда попарно равных шаров.

А это уже совершенно другое число.



#78908 Опыты по Теории Вероятностей

Отправлено автор: LKhiger 17 октября 2010 - 13:19 в IBM DB2

Сенсация: одни и те же номера выпали в "Лото" два раза за месяц

В минувшую субботу состоялся очередной розыгрыш лотереи "Лото". Выиграли номера 13, 14, 26, 32, 33 и 36. Следует отметить, что те же самые числа выпадали на розыгрыше, состоявшемся менее месяца назад – 21 сентября.

По мнению специалистов, статистическая вероятность такого события составляет 0,00000000000025.

При этом число победителей оказалось намного больше обычного.
Не менее 92 человек решили, что выигравшие один раз числа выпадут снова, и отметили их.
Правда, лишь трое из них угадали дополнительный номер – 2 (миспар хазак), и каждый из них получит по четыре миллиона шекелей. Дополнительный номер, выпавший в сентябре, был 1.

Число угадавших правильно 5 номеров и дополнительный составило 14 человек, каждый из них получит 6.561 шекелей.

http://www.newsru.co...0/loto8005.html

Вопрос: :rtfm:
Правильно ли "учёные" подсчитали вероятность этого события ?



#78899 Опыты по Теории Вероятностей

Отправлено автор: LKhiger 16 октября 2010 - 10:22 в IBM DB2

Change RandInt function, override RandInt

The function RandInt(integer) is working now in intervals:
[0, X] when X > 0
[X, 0] when X < 0
[0, 1] when X in (0, 1)

drop function RandInt(integer);

CREATE FUNCTION RandInt (X integer) 
RETURNS integer 
LANGUAGE SQL 
CONTAINS SQL 
NO EXTERNAL ACTION 
not DETERMINISTIC 
RETURN 
case when X = 0 
then int(1 * Rand() + .5)
else int(X * Rand() + 0.5 * sign(X))
end
;

The function RandInt(integer, integer) is overriding RandInt(integer) and
working in intervals:
[start#, end#] when end# >= start#
[end#, start#] when end# <= start#

CREATE FUNCTION RandInt (start# integer, end# integer) 
RETURNS integer 
LANGUAGE SQL 
CONTAINS SQL 
NO EXTERNAL ACTION 
not DETERMINISTIC 
RETURN RandInt(end# - start#) + start#;

What could be also interesting to us:
Create statement of RandInt(integer, integer) function consists call to
parent function RandInt(integer).

Example of using new functions:

select 
randint(500) int1, randint(1000) int2, randint(500, 1000) int3
from sysibm.sysdummy1;



#78794 Опыты по Теории Вероятностей

Отправлено автор: LKhiger 14 октября 2010 - 03:22 в IBM DB2


Испытайте сами на своём компьютере и убедитесь как близко математическое ожидание к середине


А что, функция RAND возвращает случайное число?
Или всё-таки псевдослучайное? ;)

Здравствуйте !

Приятная неожиданность. Я здесь не один ! :good:

Конечно псевдослучайное. Но на это можно не обращать внимание.

Когда я в 1994 году для одной солидной американской компании делал проект, в котором потребовалась случайная выборка, а DB2 версия 3 не имела функции RAND(), я сам создал такую "функцию" и все были счастливы.

Хотя и UDF функций тогда не было.

:ok: Работаем с тем, что имеем. :ok:

Lenny



#78763 Опыты по Теории Вероятностей

Отправлено автор: LKhiger 13 октября 2010 - 12:01 в IBM DB2

Случайные перестановки букв в слове:

with Input (word) as 
(select 'database2' from sysibm.sysdummy1
)
,
RandCharOrder (randword, remword, k) as
(select varchar('', 1000), strip(word), length(word)  
   from Input
union all
select randword || substr(remword, pos, 1), 
case when pos = 1 and length(remword) > 1
     then substr(remword, pos + 1)
     when length(remword) = 1
     then remword
     else substr(remword, 1, pos - 1) || substr(remword, pos + 1)
end, ch.k - 1
from RandCharOrder ch, Input, 
table
(select randint(length(remword) - 1) + 1 pos, ch.k
from sysibm.sysdummy1 ) rr

Where length(remword) > 0 and ch.k - 1 >= 0 
) 
select word, randword from RandCharOrder, Input
where k = 0
:focus:



#78713 Опыты по Теории Вероятностей

Отправлено автор: LKhiger 11 октября 2010 - 16:27 в IBM DB2

Моделирование броска кости.

Можно сделать красивее:


select gm.dice
from
(select randint(5) + 1 rdc from sysibm.sysdummy1) dce
join table
(
select case when rdc = 1 then '    '
                 when rdc = 2 then  ' * '
                 when rdc = 3 then  '*  '
                 when rdc = 4 then  '* *'
                 when rdc = 5 then  '* *'
                 when rdc = 6 then  '** '
       end dice
from sysibm.sysdummy1

union all

select case when rdc = 1 then  ' * '
                 when rdc = 2 then  '    '
                 when rdc = 3 then  ' * '
                 when rdc = 4 then  '    '
                 when rdc = 5 then  ' * '
                 when rdc = 6 then  '** '
       end dice
from sysibm.sysdummy1

union all

select case when rdc = 1 then  '   '
                 when rdc = 2 then  ' * '
                 when rdc = 3 then  '  *'
                 when rdc = 4 then  '* *'
                 when rdc = 5 then  '* *'
                 when rdc = 6 then  '** '
       end dice
from sysibm.sysdummy1
) gm
On 1 = 1
;
:diablo: :good:



#78707 Опыты по Теории Вероятностей

Отправлено автор: LKhiger 11 октября 2010 - 13:44 в IBM DB2

Моделирование броска кости.

Как известно, может выпасть от 1 до 6:

select case when dice = 1 then 'One'
when dice = 2 then 'Two'
when dice = 3 then 'Three'
when dice = 4 then 'Four'
when dice = 5 then 'Five'
else 'Six'
end "Game With Dice" 
from
(select randint(5) + 1 dice from sysibm.sysdummy1) dce;



#78680 Опыты по Теории Вероятностей

Отправлено автор: LKhiger 11 октября 2010 - 01:55 в IBM DB2

Опыты по Теории Вероятностей

Для наших опытов создадим очень простую функцию, которая случайным образом будет возвращать целые числа в интервале, заданном входным параметром:

drop function RandInt;

CREATE FUNCTION RandInt (X integer) 
RETURNS integer 
LANGUAGE SQL 
CONTAINS SQL 
NO EXTERNAL ACTION 
not DETERMINISTIC 
RETURN int(X * Rand() + .5);
В принципе её можно не создавать, но она сильно упрощает задачу и делает решение красивее и доступней для понимания.

Так RandInt(1) иммитирует бросание монеты: 0 - решка, 1 - орёл.

Подбросим монетку:

select case when randint(test) = 0 then 'Tail'
            else 'Head'
       end "Game With Dime" 
from
(select 1 test from sysibm.sysdummy1) tst;

Где Tail - Решка, а Head соответсвенно - Орёл

Будем подбрасывать её много раз (например 10000 раз), чтобы найти Математическое Ожидание.

Наверное устанем, если не используем возможности

with prob (k, maxK, total) as
(select 0, 10000, 0 from sysibm.sysdummy1
union all
select k + 1, maxK, total + randint(1)
from prob
where k + 1 <= maxK
) 
select maxK, total from prob
where k = maxK;
Испытайте сами на своём компьютере и убедитесь как близко математическое ожидание к середине
10000 / 2 = 5000

Lenny



#78672 MegaSUDOKU killer

Отправлено автор: LKhiger 09 октября 2010 - 10:58 в IBM DB2

The Query found 283576 solutions for this simple input.
The Query had worked for 2 hrs 3min 26 sec:
:diablo:

select max(sd_id) from final table
(insert into Sd_Source  
select ifnull(max(sd_id), 0) + 1, 1, '123000000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())       
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 2, '456000000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 3, '789000000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all 
select ifnull(max(sd_id), 0) + 1, 4, '000123000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 5, '000456000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 6, '000789000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 7, '000000123'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 8, '000000456'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 9, '000000789'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
);

select sudoku_solution from SDVW_SOLUTION;

Results:

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

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

.................................................. ..........................
................ 283572 other solutions ............................
.................................................. ..........................

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

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


Lenny :ok:



#77867 MegaSUDOKU killer

Отправлено автор: LKhiger 09 сентября 2010 - 01:21 в IBM DB2

/* 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
After insert into table, you can select sudoku_solution from SDVW_SOLUTION
*/
:diablo:

select max(sd_id) from final table
(insert into Sd_Source  
select ifnull(max(sd_id), 0) + 1, 1, '060030008'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())       
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 2, '000060040'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 3, '029000000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all 
select ifnull(max(sd_id), 0) + 1, 4, '008200100'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 5, '500040006'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 6, '001008700'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 7, '004000380'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 8, '030000000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 9, '700090025'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
);

select sudoku_solution from SDVW_SOLUTION;

Result:

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



Lenny :good:



#77495 MegaSUDOKU killer

Отправлено автор: LKhiger 14 августа 2010 - 13:05 в IBM DB2

Why Friday's Sudoku ?

Because on Friday "AM" NY usually publish Level-4 Sudoku, any other levels for My Solver like sunflower seeds for elephant.
:victory:

select max(sd_id) from final table
(insert into Sd_Source  
select ifnull(max(sd_id), 0) + 1, 1, '000000000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())       
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 2, '020508030'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 3, '030090004'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all 
select ifnull(max(sd_id), 0) + 1, 4, '800305062'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 5, '000800000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 6, '570904008'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 7, '600050070'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 8, '080701050'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 9, '400000000'
     , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
);

select sudoku_solution from SDVW_SOLUTION;

Result:

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


Lenny



#76696 MegaSUDOKU killer

Отправлено автор: LKhiger 04 июля 2010 - 13:52 в IBM DB2

Level: "Hard" Sudoku from "Metro", NY: :victory:

select max(sd_id) from final table
(insert into Sd_Source  
select ifnull(max(sd_id), 0) + 1, 1, '304701500'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())	   
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 2, '000000070'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 3, '000005803'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all 
select ifnull(max(sd_id), 0) + 1, 4, '000850109'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 5, '005127300'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 6, '801039000'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 7, '602900000'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 8, '070000000'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 9, '009608207'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
);

select sudoku_solution from SDVW_SOLUTION;

Result:

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



Lenny



#76548 Генератор лотерейных номеров

Отправлено автор: LKhiger 26 июня 2010 - 11:51 в IBM DB2

Pick 10 from 80 (New York)

Select 10 numbers from 1 through 80....


with Pick_10_NY
(tickets, R, K, Lsw, L1, L2, L3, L4, L5, L6, L7, L8, L9, L10 ) as
(select int(20),int(0),int(0), 'N',
		char('', 2), char('', 2), char('', 2),   
		char('', 2), char('', 2), char('', 2),
		char('', 2), char('', 2), char('', 2), 
		char('', 2)			   
   from sysibm.sysdummy1 
union all
select 
tickets, 
R + 20, 
	K + case when M1  > '00' and M2 > '00' and M3 > '00' and 
				  M4  > '00' and M5 > '00' and M6 > '00' and
				  M7  > '00' and M8 > '00' and M9 > '00' and
				  M10 > '00'
			 then 1
			 else 0
		end,
case when M1  > '00' and M2 > '00' and M3 > '00' and 
		  M4  > '00' and M5 > '00' and M6 > '00' and
		  M7  > '00' and M8 > '00' and M9 > '00' and
		  M10 > '00'
	 then 'Y'
	 else 'N'
end,
M1, M2, M3, M4, M5, M6, M7, M8, M9, M10 
from Pick_10_NY lt,
table (
select max(L1)  M1, max(L2) M2, max(L3) M3, 
	   max(L4)  M4, max(L5) M5, max(L6) M6, 
	   max(L7)  M7, max(L8) M8, max(L9) M9,
	   max(L10) M10   
from 
(select  L1, L2, L3, L4, L5, L6, L7, L8, L9, L10  
from
(select  L1, L2, L3, L4, L5, L6, L7, L8, L9, L10  
from
(select 
		substr(char(rand(R)),  3,  1)	 ||  
substr(char(rand(R + 1)),  4,  1)  L1, 
		substr(char(rand(R + 2)),  5,  1) ||  
substr(char(rand(R + 3)),  6,  1)  L2, 
		substr(char(rand(R + 4)),  7,  1) ||  
substr(char(rand(R + 5)),  8,  1)  L3, 
		substr(char(rand(R + 6)),  9,  1) ||  
substr(char(rand(R + 7)),  10, 1)  L4,
		substr(char(rand(R + 8)),  10, 1) ||  
substr(char(rand(R + 9)),  11, 1)  L5,
		substr(char(rand(R + 10)), 12, 1) ||  
substr(char(rand(R + 11)), 13, 1)  L6, 
		substr(char(rand(R + 12)), 14, 1) ||  
substr(char(rand(R + 13)), 15, 1)  L7,  
		substr(char(rand(R + 14)), 3,  1) ||  
substr(char(rand(R + 15)), 4, 1)  L8,  
		substr(char(rand(R + 16)), 5,  1) ||  
substr(char(rand(R + 17)), 6, 1)  L9, 
		substr(char(rand(R + 18)), 7,  1) ||  
substr(char(rand(R + 19)), 8, 1) L10 
from sysibm.sysdummy1 ) rd1
where 
L1  between '01' and '80' and
L2  between '01' and '80' and
L3  between '01' and '80' and
L4  between '01' and '80' and
L5  between '01' and '80' and
L6  between '01' and '80' and
L7  between '01' and '80' and
L8  between '01' and '80' and
L9  between '01' and '80' and
L10 between '01' and '80' 
) rd2 
Where 
L1  not in (L2, L3, L4, L5, L6, L7, L8, L9, L10) and
L2  not in (L1, L3, L4, L5, L6, L7, L8, L9, L10) and
L3  not in (L1, L2, L4, L5, L6, L7, L8, L9, L10) and
L4  not in (L1, L2, L3, L5, L6, L7, L8, L9, L10) and
L5  not in (L1, L2, L3, L4, L6, L7, L8, L9, L10) and
L6  not in (L1, L2, L3, L4, L5, L7, L8, L9, L10) and
L7  not in (L1, L2, L3, L4, L5, L6, L8, L9, L10) and
L8  not in (L1, L2, L3, L4, L5, L6, L7, L9, L10) and
L9  not in (L1, L2, L3, L4, L5, L6, L7, L8, L10) and
L10 not in (L1, L2, L3, L4, L5, L6, L7, L8, L9 )
union all
select '00' L1, '00' L2, '00' L3, '00' L4, '00' L5, '00' L6, 
	   '00' L7, '00' L8, '00' L9, '00' L10
from sysibm.sysdummy1 ) rd3 ) rdm
where K <= tickets - 1
) 
select L1, L2, L3, L4, L5, L6, L7, L8, L9, L10  
  from Pick_10_NY 
   where Lsw = 'Y'
order by 1;

Result:

L1 L2 L3 L4 L5 L6 L7 L8 L9 L10

11 33 07 06 69 31 48 17 53 34
14 30 47 32 80 25 34 20 66 45
17 50 48 07 44 30 80 06 26 27
21 69 09 39 80 13 66 46 15 61
21 68 12 37 09 39 51 24 27 15
23 75 11 72 07 13 14 60 65 71
24 56 01 47 11 18 43 21 03 04
33 49 29 10 68 13 06 48 71 75
39 41 17 24 13 33 26 55 29 67
40 77 61 25 68 52 37 65 76 51
42 44 33 05 34 66 17 70 46 54
42 59 08 62 05 38 11 51 75 69
44 28 55 46 47 65 39 49 09 02
46 63 59 26 42 27 62 35 54 17
46 18 36 59 26 22 61 38 48 04
60 40 45 77 05 39 20 43 25 61
65 40 04 62 78 21 07 18 20 17
72 46 57 51 79 28 76 73 56 64
77 18 46 25 65 45 06 56 53 02
78 64 61 39 74 01 29 14 03 27


Lenny



#76385 Простой DB2 SQL для нахождения простых чисел

Отправлено автор: LKhiger 19 июня 2010 - 17:20 в IBM DB2

Галине Т. - девушке из Минска ! :clapping:

Разложение на простые множители очень больших чисел с очень большой скоростью:

with number (number) as 
(select decimal(277945762500, 15, 0) from sysibm.sysdummy1
)
,
fact1(fact) as
(
select decimal(3, 15, 0)   from sysibm.sysdummy1
union all
select fact + 2 
from fact1, number
where fact + 2 <= sqrt(number) + 1
)  
,
factors(fact) as 
(
select 2 from sysibm.sysdummy1
union all
select * from fact1
)  
,
Prime_Factorization (in_number, remd, fact) as
(select number, number, 1 
   from number
union all
select in_number, decimal(pf.remd / coalesce(f1.fact, pf.remd) , 15, 0), 
	  coalesce(f1.fact, pf.remd) 
  from Prime_Factorization pf, 
  table (select min(f2.fact) fact 
		 from factors f2 
		 where mod(pf.remd, f2.fact) = 0  
			and f2.fact <= sqrt(pf.remd) + 1  ) f1
where pf.remd > 1  
) 
select distinct in_number "Number", 
nullif(0, 0) "Prime Factor", nullif(0, 0) "Factor Power"  
from Prime_Factorization 
union all
select nullif(0, 0) "Number", fact "Prime Factor", count(*) "Factor Power" 
from Prime_Factorization 
where fact > 1
group by fact

Number......... Prime Factor......... Factor Power
277945762500
.......................... 2........................... 2
.......................... 3........................... 3
.......................... 5........................... 5
.......................... 7........................... 7


Это результат означает что 277945762500 = 2^2 * 3^3 * 5^5 * 7^7. Можете проверить.

Лёня Х.



#75888 MegaSUDOKU killer

Отправлено автор: LKhiger 22 мая 2010 - 23:11 в IBM DB2

Level-4 Sudoku. AMNY 05/21/2010 <5 sec>:

select max(sd_id) from final table
(insert into Sd_Source  
select ifnull(max(sd_id), 0) + 1, 1, '790030400'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())	   
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 2, '058000200'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 3, '000000006'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all 
select ifnull(max(sd_id), 0) + 1, 4, '900010008'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 5, '000987000'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 6, '200050007'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 7, '300000000'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 8, '029000840'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 9, '006020059'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
);

Result:

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



Sudoku Level: Hard Metro NY 05/21/2010 <0 sec>:

select max(sd_id) from final table
(insert into Sd_Source  
select ifnull(max(sd_id), 0) + 1, 1, '002059100'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())	   
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 2, '140080000'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 3, '003004008'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all 
select ifnull(max(sd_id), 0) + 1, 4, '200093080'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 5, '008000500'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 6, '050720003'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 7, '500400600'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 8, '000060041'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 9, '006930800'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
);

Result:

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



#75427 MegaSUDOKU killer

Отправлено автор: LKhiger 25 апреля 2010 - 16:27 в IBM DB2

Friday Apr 23 2010 Sudoku:

select max(sd_id) from final table
(insert into Sd_Source  
select ifnull(max(sd_id), 0) + 1, 1, '640900030'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())	   
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 2, '000000010'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 3, '000400200'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all 
select ifnull(max(sd_id), 0) + 1, 4, '010000005'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 5, '000067004'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 6, '500030090'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 7, '007004000'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 8, '030000000'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 9, '090000827'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source );


Result:

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



Lenny



#74659 MegaSUDOKU killer

Отправлено автор: LKhiger 25 марта 2010 - 03:20 в IBM DB2

Level-3 Sudoku < 0 sec >:

select max(sd_id) from final table
(insert into Sd_Source  
select ifnull(max(sd_id), 0) + 1, 1, '140007200'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())	   
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 2, '300020001'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 3, '000900070'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all 
select ifnull(max(sd_id), 0) + 1, 4, '016000000'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 5, '008105300'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 6, '000000060'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 7, '020009000'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 8, '601070008'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
union all
select ifnull(max(sd_id), 0) + 1, 9, '009500040'
	 , ifnull(max(sd_id), 0) + 1, timestamp(generate_unique())
  from Sd_Source 
);

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



Lenny