Public Zone 公開區 > Bookwyrm 書蟲天地

Einstein riddle

(1/2) > >>

hangchoi:
Just read a website and found this one. So I share here and see if you can solve it.

According to folklore, the following riddle was invented by Albert Einstein when he was just a boy. To add to its mystique, various reports suggest that only two per cent of the world's population can solve it.

Einstein riddle

There is a street with five houses all in a row. Each house has a person with a different name and each house is painted a different colour. Each homeowner drinks a different type of beverage, owns a different type of pet and reads a different type of newspaper.

Here are the clues to help you solve the puzzle :


1. Jez lives in the red house.
2. Liz keeps corgis as pets.
3. Vlad drinks vodka.
4. The green house is on the immediate left of the white house.
5. The green house's owner drinks coffee.
6. The owner who reads the Morning Star keeps a golden eagle.
7. The owner of the purple house reads the Daily Express.
8. The owner living in the centre house drinks milk.
9. Nigel lives in the first house.
10. The owner who reads the Guardian lives next to the one who keeps a tiger.
11. The owner who keeps the stallion lives next to the one who reads the Daily Express.
12. The owner who reads the Times drinks beer.
13. Donald reads the Daily Mail.
14. Nigel lives next to the blue house.
15. The owner who reads the Guardian lives next to the one who drinks green tea.

Now, the question is : Who owns the goldfish?

______________________________________________

I solved it in 10 minutes so I really doubt those reports.

Will let you know the answer, if you can't figure it out, which I don't think you can't.

Enjoy!!!

chin:
corgi, eagle, tiger, stallion.

whose says there is a goldfish. do we assume the goldfish is the 5th one?

if yes, can you simple draw a chart?

hangchoi:
Yes, there are totally 5 pets kept by those home-owners. Goldfish is the fifth one.

well. drawing a chart is one way to solve the riddle. You may give it a go.

q:
I think I have the answer... took me 9:59.9999 minutes   ;D

kido:
Interestingly, I have a solution, in 18ms, LOL. :o

I solved it, with the help of a computer, which the solution comes out instantaneously, in 18ms.


--- Code: ---| ?- solution(Houses).

Houses = [(nigel,purple,tiger,green_tea,daily_express),(vlad,blue,stallion,vodka,guardian),(jez,red,eagle,milk,morning_star),(donald,green,fish,coffee,daily_mail),(liz,white,corgis,beer,times)] ? a

(18 ms) no

--- End code ---

The above is a list containing the solution, first tuple is the first house's characteristics, etc.  It's a Prolog program.


[hide]

For those who are interested, here is the code:


--- Code: ---%
% Space of possible answers.
%
houses(0, []) :- !.
houses(N, [(_Name,_Color,_Pet,_Drink,_Read)|T]) :- N1 is N-1, houses(N1,T).

% get the N-th member from a sequence
seq(1, [H|_], H) :- !.
seq(N, [_|T], R) :- N1 is N-1, seq(N1,T,R).

% 1. Jez lives in the red house.
db1( [(jez,red,_,_,_) | _] ).
db1( [_|T] ) :- db1(T).

% 2. Liz keeps corgis as pets.
db2( [(liz,_,corgis,_,_) | _] ).
db2( [_|T] ) :- db2(T).

% 3. Vlad drinks vodka.
db3( [(vlad,_,_,vodka,_)| _] ).
db3( [_|T] ) :- db3(T).

% 4. The green house is on the immediate left of the white house.
db4( [(_,green,_,_,_),(_,white,_,_,_)|_] ).
db4( [_|T] ) :- db4(T).

% 5. The green house's owner drinks coffee.
db5( [(_,green,_,coffee,_)|_] ).
db5( [_|T] ) :- db5(T).

% 6. The owner who reads the Morning Star keeps a golden eagle.
db6( [(_,_,eagle,_,morning_star)|_] ).
db6( [_|T] ) :- db6(T).

% 7. The owner of the purple house reads the Daily Express.
db7( [(_,purple,_,_,daily_express)|_] ).
db7( [_|T] ) :- db7(T).

% 8. The owner living in the centre house drinks milk.
db8( Houses ) :- seq( 3, Houses, (_,_,_,milk,_) ).

% 9. Nigel lives in the first house
db9( Houses ) :- seq( 1, Houses, (nigel,_,_,_,_) ).

% 10. The owner who reads the Guardian lives next to the one who keeps a tiger.
db10( [(_,_,_,_,guardian),(_,_,tiger,_,_)|_] ).
db10( [(_,_,tiger,_,_),(_,_,_,_,guardian)|_] ).
db10( [_|T] ) :- db10(T).

% 11. The owner who keeps the stallion lives next to the one who reads the Daily Express.
db11( [(_,_,_,_,daily_express),(_,_,stallion,_,_)|_] ).
db11( [(_,_,stallion,_,_),(_,_,_,_,daily_express)|_] ).
db11( [_|T] ) :- db11(T).

% 12. The owner who reads the Times drinks beer.
db12( [(_,_,_,beer,times)|_] ).
db12( [_|T] ) :- db12(T).

% 13. Donald reads the Daily Mail.
db13( [(donald,_,_,_,daily_mail)|_] ).
db13( [_|T] ) :- db13(T).

% 14. Nigel lives next to the blue house.
db14( [(nigel,_,_,_,_),(_,blue,_,_,_)|_] ).
db14( [(_,blue,_,_,_),(nigel,_,_,_,_)|_] ).
db14( [_|T] ) :- db14(T).

% 15. The owner who reads the Guardian lives next to the one who drinks green tea.
db15( [(_,_,_,_,guardian),(_,_,_,green_tea,_)|_] ).
db15( [(_,_,_,green_tea,_),(_,_,_,_,guardian)|_] ).
db15( [_|T] ) :- db15(T).

% Who owns the goldfish?
question( [(_,_,fish,_,_)|_] ).
question( [_|T] ) :- question(T).

solution(Houses) :-
houses(5,Houses),
db1(Houses),
db2(Houses),
db3(Houses),
db4(Houses),
db5(Houses),
db6(Houses),
db7(Houses),
db8(Houses),
db9(Houses),
db10(Houses),
db11(Houses),
db12(Houses),
db13(Houses),
db14(Houses),
db15(Houses),
question(Houses).

--- End code ---
[/hide]

Navigation

[0] Message Index

[#] Next page

Go to full version