posted 12/31/2009 by Rami Reddy
Today Morning one of my Colleague gave me this puzzle....
ALBERT EINSTEIN'S RIDDLEARE YOU IN THE TOP 2% OF INTELLIGENT PEOPLE IN THE WORLD?SOLVE THE RIDDLE AND FIND OUT.There are no tricks, just pure logic, so good luck and don't give up.1. In a street there are five houses, painted five different colors.2. In each house lives a person of different nationality3. These five homeowners each drink a different kind of beverage, smoke different brand of cigar and keep a different pet.THE QUESTION: WHO OWNS THE FISH?HINTS 1. The British man lives in a red house. 2. The Swedish man keeps dogs as pets. 3. The Danish man drinks tea. 4. The Green house is next to, and on the left of the White house. 5. The owner of the Green house drinks coffee. 6. The person who smokes Pall Mall rears birds. 7. The owner of the Yellow house smokes Dunhill. 8. The man living in the center house drinks milk. 9. The Norwegian lives in the first house. 10. The man who smokes Blends lives next to the one who keeps cats. 11. The man who keeps horses lives next to the man who smokes Dunhill. 12. The man who smokes Blue Master drinks beer. 13. The German smokes Prince. 14. The Norwegian lives next to the blue house. 15. The Blends smoker lives next to the one who drinks water.
I faced same kind of question in a competition exam some years back... I solved it manually at that time.... But these days, I don't have patience to solve it again manually.... So i tried to solve in a different approach through a single sql query....
After wasting a lot of time, I got the solution finally...
;with N as
select 1 as Num union all select 2 union all select 3 union all select 4 union all select 5
select N1.Num as Pet , N2.Num as Person , N3.Num as Color , N4.Num as Drink, N5.Num as Smoke from N N1,N N2,N N3,N N4,N N5
select * from Houses where
( ( Person = 1 and Color = 1) or (Person <> 1 and Color <> 1)) and
( ( Person = 2 and Pet = 1) or (Person <> 2 and Pet <> 1)) and
( ( Person = 3 and Drink = 1) or (Person <> 3 and Drink <> 1)) and
( ( Color = 2 and Drink = 2) or (Color <> 2 and Drink <> 2)) and
( ( Smoke = 1 and Pet = 2) or (Smoke <> 1 and Pet <> 2)) and
( ( Color = 3 and Smoke = 2) or (Color <> 3 and Smoke <> 2)) and
( ( Drink = 5 and Smoke = 5) or (Smoke <> 5 and Drink <> 5)) and
( ( Person = 4 and Smoke = 3) or (Person <> 4 and Smoke <> 3))
--select * from House
select H1.Pet as Pet1,H1.Color as Color1 ,H1.Person AS Person1,H1.Drink AS Drink1,H1.Smoke as Smoke1,
H2.Pet as Pet2,H2.Color as Color2 ,H2.Person AS Person2,H2.Drink AS Drink2,H2.Smoke as Smoke2,
H3.Pet as Pet3,H3.Color as Color3 ,H3.Person AS Person3,H3.Drink AS Drink3,H3.Smoke as Smoke3,
H4.Pet as Pet4,H4.Color as Color4 ,H4.Person AS Person4,H4.Drink AS Drink4,H4.Smoke as Smoke4,
H5.Pet as Pet5,H5.Color as Color5 ,H5.Person AS Person5,H5.Drink AS Drink5,H5.Smoke as Smoke5
from House H1,House H2,House H3,House H4,House H5
where H3.Drink = 4 and H1.Person = 5
and H1.Pet + H2.Pet + H3.Pet + H4.Pet + H5.Pet = 15 and H1.Pet * H2.Pet * H3.Pet * H4.Pet * H5.Pet = 120
and H1.Color + H2.Color + H3.Color + H4.Color + H5.Color = 15 and H1.Color * H2.Color * H3.Color * H4.Color * H5.Color = 120
and H1.Smoke + H2.Smoke + H3.Smoke + H4.Smoke + H5.Smoke = 15 and H1.Smoke * H2.Smoke * H3.Smoke * H4.Smoke * H5.Smoke = 120
and H1.Drink + H2.Drink + H3.Drink + H4.Drink + H5.Drink = 15 and H1.Drink * H2.Drink * H3.Drink * H4.Drink * H5.Drink = 120
and H1.Person + H2.Person + H3.Person + H4.Person + H5.Person = 15 and H1.Person * H2.Person * H3.Person * H4.Person * H5.Person = 120
and ( (H1.Color = 2 and H2.Color = 5) or (H2.Color = 2 and H3.Color = 5) or (H3.Color = 2 and H4.Color = 5) or (H4.Color = 2 and H5.Color = 5))
and ( (H1.Pet = 4 and H2.Smoke = 4) or (H2.Pet = 4 and H3.Smoke = 4) or (H3.Pet = 4 and H4.Smoke = 4) or (H4.Pet = 4 and H5.Smoke = 4) or (H5.Pet = 4 and H1.Smoke = 4))
and ( (H2.Pet = 3 and H1.Smoke = 2) or (H3.Pet = 3 and H2.Smoke = 2) or (H4.Pet = 3 and H3.Smoke = 2) or (H5.Pet = 3 and H4.Smoke = 2))
and ( (H2.Color = 4 and H1.Person = 5) )
and ( (H1.Drink = 3 and H2.Smoke = 4) or (H2.Drink = 3 and H3.Smoke = 4) or (H3.Drink = 3 and H4.Smoke = 4) or (H4.Drink = 3 and H5.Smoke = 4) )
select 'House1' as House,Pet1 as Pet,Color1 as Color,Person1 as Person,Drink1 as Drink,Smoke1 as Smoke from Result
select 'House2',Pet2,Color2,Person2,Drink2,Smoke2 from Result
select 'House3',Pet3,Color3,Person3,Drink3,Smoke3 from Result
select 'House4',Pet4,Color4,Person4,Drink4,Smoke4 from Result
select 'House5',Pet5,Color5,Person5,Drink5,Smoke5 from Result
select 'Pet' as [Type],1 as Id,'Dog' as [Name] union all select 'Pet',2,'Bird' union all select 'Pet',3,'Horse' union all select 'Pet',4,'Cat' union all select 'Pet',5,'Fish' union all
select 'Person',1,'British' union all select 'Person',2,'Sweedish' union all select 'Person',3,'Danish' union all select 'Person',4,'German' union all select 'Person',5,'Norway' union all
select 'Color',1,'Red' union all select 'Color',2,'Green' union all select 'Color',3,'Yellow' union all select 'Color',4,'Blue' union all select 'Color',5,'White' union all
select 'Drink',1,'Tea' union all select 'Drink',2,'Coffee' union all select 'Drink',3,'Water' union all select 'Drink',4,'Milk' union all select 'Drink',5,'Beer' union all
select 'Smoke',1,'PallMall' union all select 'Smoke',2,'Dunhill' union all select 'Smoke',3,'Prince' union all select 'Smoke',4,'Blend' union all select 'Smoke',5,'BlueMaster'
(select Name from Data where Id = Pet and [Type] = 'Pet') as Pet,
(select Name from Data where Id = Drink and [Type] = 'Drink') as Drink,
(select Name from Data where Id = Smoke and [Type] = 'Smoke') as Smoke,
(select Name from Data where Id = Person and [Type] = 'Person') as Person,
(select Name from Data where Id = Color and [Type] = 'Color') as Color
from TabularFormat T
answer it gave:
House1 Cat Water Dunhill Norway Yellow
House2 Horse Tea Blend Danish Blue
House3 Bird Milk PallMall British Red
House4 Fish Coffee Prince German Green
House5 Dog Beer BlueMaster Sweedish White
A Computer, which will not have any intelligence(Which just will do what we will tell) solved this problem....
So, I am sure that more than 2% of people can solve this....
What kind of email newsletter would you prefer to receive from CodeAsp.Net?