powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Oracle [игнор отключен] [закрыт для гостей] / Загадка Эйнштейна средствами Oracle
7 сообщений из 7, страница 1 из 1
Загадка Эйнштейна средствами Oracle
    #39737449
Est_vopros
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
На одной улице подряд стоят пять домов, каждый — своего цвета. В каждом живёт человек, все пять — разных национальностей. Каждый человек предпочитает уникальную марку сигарет, напиток и домашнее животное. Кроме того:

Норвежец живёт в первом доме.
Англичанин живёт в красном доме.
Зелёный дом находится слева от белого, рядом с ним.
Датчанин пьёт чай.
Тот, кто курит Rothmans, живёт рядом с тем, кто выращивает кошек.
Тот, кто живёт в жёлтом доме, курит Dunhill.
Немец курит Marlboro.
Тот, кто живёт в центре, пьёт молоко.
Сосед того, кто курит Rothmans, пьёт воду.
Тот, кто курит Pall Mall, выращивает птиц.
Швед выращивает собак.
Норвежец живёт рядом с синим домом.
Тот, кто выращивает лошадей, живёт в синем доме.
Тот, кто курит Philip Morris, пьет пиво.
В зелёном доме пьют кофе.
Вопрос:
Кто разводит рыбок?

Заготовка:
Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
with tn as (select 'Norwegian' n  from dual union all    
            select 'Englishman' from dual union all    
            select 'Dane' from dual union all    
            select 'German' from dual union all    
            select 'Swede' from dual            ),    
     thn as (select 1 hn  from dual  union all    
             select 2 from dual union all    
             select 3 from dual union all    
             select 4 from dual union all    
             select 5 from dual ),    
      thc as (select 'red' hc from dual union all    
              select 'green' from dual  union all    
              select 'white' from dual   union all    
              select 'yellow' from dual  union all    
              select 'blue' from dual  ),    
      tdr as (select 'tea' dr from dual union all    
              select 'milk' from dual union all    
              select 'water' from dual union all    
              select 'beer' from dual union all    
              select 'coffee' from dual),    
      ts as (select 'Rothmans' s from dual union all    
             select 'Dunhill' s from dual union all    
             select 'Marlboro' s from dual union all    
             select 'Pall Mall' s from dual union all    
             select 'Philip Morris' s from dual ),    
      tp as (select 'cat' pet from dual union all    
             select 'bird' pet from dual union all    
             select 'dog' pet from dual  union all    
             select 'horse' pet from dual  union all    
             select 'fish' pet from dual    
      ),    
tc1 as (select n,hn,hc,dr,s,pet from tn,thn,thc,tdr,ts,tp    
where    
 ((hn =  1 and n =  'Norwegian') or (hn <> 1 and n <> 'Norwegian'))    
and    
 ((hc =  'red'  and n =  'Englishman') or(hc <> 'red'  and n <> 'Englishman'))    
and   
 ((n =  'Dane' and dr =  'tea') or    (n <> 'Dane' and dr <> 'tea'))    
and    
 ((hc =  'yellow' and s =  'Dunhill') or (hc <> 'yellow' and s <> 'Dunhill'))  
and  
 ((n =  'German' and s =  'Marlboro') or  (n <> 'German' and s <> 'Marlboro'))  
and  
 ((hn =  3 and dr =  'milk' ) or  (hn <> 3 and dr <> 'milk' ))  
and  
 ((s =  'Pall Mall' and pet =  'bird') or  (s <> 'Pall Mall' and pet <> 'bird'))  
and  
 ((n =  'Swede' and pet =  'dog') or (n <> 'Swede' and pet <> 'dog'))  
and  
 ((pet =  'horse' and hc =  'blue') or (pet <> 'horse' and hc <> 'blue'))  
and  
 ((s =  'Philip Morris' and  dr =  'beer') or (s <> 'Philip Morris' and  dr <> 'beer'))  
and  
 ((hc =  'green' and dr =  'coffee') or  (hc <> 'green' and dr <> 'coffee'))
)
                                    
,ut_3 as  (select * from tc1 tc1_1 where (hc =  'green'  and not exists (select 1 from tc1 where hn = tc1_1.hn+1 and hc = 'white')) or    
                                      (hc =  'white'  and not exists (select 1 from tc1 where hn = tc1_1.hn-1 and hc = 'green'))  
           )      
,ut_5 as  (select * from tc1 tc1_1 where (s =  'Rothmans' and not exists (select 1 from tc1 where abs(hn-tc1_1.hn) = 1 and pet =  'cat' )) or    
                                      (pet  = 'cat'    and not exists (select 1 from tc1 where abs(hn-tc1_1.hn) = 1 and s =  'Rothmans' ))  
         )  
,ut_9 as  (select * from tc1 tc1_1 where (s =  'Rothmans' and not exists (select 1 from tc1 where abs(hn-tc1_1.hn) = 1 and dr =  'water' )) or   
                                      (dr =  'water'   and not exists (select 1 from tc1 where abs(hn-tc1_1.hn) = 1 and s =  'Rothmans'  )) 
        )  
,ut_12 as (select * from tc1 tc1_1 where (n =  'Norwegian' and not exists (select 1 from tc1 where abs(hn-tc1_1.hn) = 1 and hc =  'blue' )) or  
                                      (hc =  'blue'  and not exists (select 1 from tc1 where abs(hn-tc1_1.hn) = 1 and  n =  'Norwegian' ))   
        )  
,tc2 as (  
select * from tc1 
minus 
select * from ut_3  
minus  
select * from ut_5  
minus  
select * from ut_9  
minus  
select * from ut_12) 
select * from tc2;




Интересуют любые решения. Особенно моделью, всякими POWERMULTISET и т.п.
Возможно ли в принципе решение на PL/Sql на объектах ООП?
P.S. рекурсией одно решение есть. Но не шустрое. Если интересно, опубликую.
...
Рейтинг: 0 / 0
Загадка Эйнштейна средствами Oracle
    #39737452
123йй
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Est_vopros,

нашел бы баян старее
...
Рейтинг: 0 / 0
Загадка Эйнштейна средствами Oracle
    #39737454
Фотография -2-
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Est_voprosвсякими POWERMULTISET и т.п.Куда их там накручивать? Все условия на связь одной сущности с другой - это традиционный джоин.

Est_voprosрешение на PL/Sql на объектах ООПобъекты отличаются от рекордов 3gl только поилморфизмом. В задаче сущности пассивны и что немцу мальборо, то лошади смерть. Если уж интересуют непривычные решения, бери пролог.
...
Рейтинг: 0 / 0
Загадка Эйнштейна средствами Oracle
    #39737549
SkilledJunior
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Est_voprosВозможно ли в принципе решение на PL/Sql на объектах ООП?
Решение начинается с алгоритма.

Est_voprosВозможно ли в принципе решение на PL/Sql
Если есть пошаговый формализованный алгоритм.
...
Рейтинг: 0 / 0
Загадка Эйнштейна средствами Oracle
    #39737630
efendi
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Est_vopros,

Не Oracle, но думаю разберешься Загадка Энштейна
...
Рейтинг: 0 / 0
Загадка Эйнштейна средствами Oracle
    #39737642
Est_vopros
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
123ййEst_vopros,

нашел бы баян старее
Спасибо! В этом баяне искал, но просмотрел это решение:
Имя пользователя1пост в закрытом форуме ((
суть:
Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
with ids as (select level id from dual connect by level <= 5),
i as (
select i1.id a, i2.id b, i3.id c, i4.id d, i5.id e
from ids i1, ids i2, ids i3, ids i4, ids i5
where i1.id <> i2.id and i1.id <> i3.id and i1.id <> i4.id and i1.id <> i5.id 
  and i2.id <> i3.id and i2.id <> i4.id and i2.id <> i5.id 
  and i3.id <> i4.id and i3.id <> i5.id 
  and i4.id <> i5.id),

nac as (select a angl, b dat, c sved, d nor, e nemec from i),
color as (select a red, b green, c yellow, d blue, e white from i),
anim as (select a dog, b cat, c kon, d bird, e RIBA from i),
drink as (select a water, b beer, c milk, d cofe, e tea from i),
cigar as (select a Bluemaster, b Dunhill, c Blend, d PM, e Prince from i)

select * from nac, color, anim, drink, cigar
where angl = red and sved = dog
  and dat = tea and green = white - 1
  and green = cofe and PM = bird
  and yellow = Dunhill and milk = 3
  and nor = 1 and abs(Blend-cat) = 1
  and abs(kon - Dunhill) = 1 and beer = Bluemaster
  and nemec = Prince and abs(nor-blue)=1
  and abs(Blend-water)=1;



Оно супер!
...
Рейтинг: 0 / 0
Загадка Эйнштейна средствами Oracle
    #39737648
Est_vopros
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
efendiEst_vopros,

Не Oracle, но думаю разберешься Загадка Энштейна
Спасибо!
...
Рейтинг: 0 / 0
7 сообщений из 7, страница 1 из 1
Форумы / Oracle [игнор отключен] [закрыт для гостей] / Загадка Эйнштейна средствами Oracle
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]