Author Topic: Einstein riddle  (Read 27485 times)

Offline hangchoi

  • SBC Old Boys
  • ***
  • Posts: 3,007
  • Alcoholic + Golfmania
    • MaJeff's Wine Blog
Einstein riddle
« on: 11 September 2015, 23:25:23 »
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!!!
「吾心信其可行,則移山倒海之難,終有成功之日。吾心信其不可行,則反掌折枝之易,亦無收效之期也。」

Offline chin

  • Global Moderator
  • *****
  • Posts: 6,663
Re: Einstein riddle
« Reply #1 on: 14 September 2015, 17:22:40 »
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?

Offline hangchoi

  • SBC Old Boys
  • ***
  • Posts: 3,007
  • Alcoholic + Golfmania
    • MaJeff's Wine Blog
Re: Einstein riddle
« Reply #2 on: 15 September 2015, 14:32:19 »
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.
「吾心信其可行,則移山倒海之難,終有成功之日。吾心信其不可行,則反掌折枝之易,亦無收效之期也。」

Offline q

  • Quan
  • ***
  • Posts: 285
Re: Einstein riddle
« Reply #3 on: 20 September 2015, 22:15:36 »
I think I have the answer... took me 9:59.9999 minutes   ;D

Offline kido

  • SBC Old Boys
  • ***
  • Posts: 310
Re: Einstein riddle
« Reply #4 on: 20 September 2015, 23:34:48 »
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: [Select]
| ?- 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

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: [Select]
%
% 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).
[/hide]
« Last Edit: 21 September 2015, 10:58:28 by kido »
Hey, diddle, diddle ! The cat and the fiddle.

Offline hangchoi

  • SBC Old Boys
  • ***
  • Posts: 3,007
  • Alcoholic + Golfmania
    • MaJeff's Wine Blog
Re: Einstein riddle
« Reply #5 on: 21 September 2015, 15:09:37 »
I think I have the answer... took me 9:59.9999 minutes   ;D

Q, you should be far smarter than me. How come you solved it just 0.0001 sec faster? I expect you can solve it without drawing a chart in 1 minute.  >:(
「吾心信其可行,則移山倒海之難,終有成功之日。吾心信其不可行,則反掌折枝之易,亦無收效之期也。」

Offline hangchoi

  • SBC Old Boys
  • ***
  • Posts: 3,007
  • Alcoholic + Golfmania
    • MaJeff's Wine Blog
Re: Einstein riddle
« Reply #6 on: 21 September 2015, 15:23:50 »
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: [Select]
| ?- 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

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


 


You should start counting when you write the program.......  8)
「吾心信其可行,則移山倒海之難,終有成功之日。吾心信其不可行,則反掌折枝之易,亦無收效之期也。」

Offline kido

  • SBC Old Boys
  • ***
  • Posts: 310
Re: Einstein riddle
« Reply #7 on: 21 September 2015, 15:28:00 »

You should start counting when you write the program.......  8)

ok, ok, I confess.  I used 3+ hrs to write it up.
Hey, diddle, diddle ! The cat and the fiddle.

Offline wongyan

  • SBC Old Boys
  • ***
  • Posts: 552
Re: Einstein riddle
« Reply #8 on: 23 September 2015, 10:54:18 »
you guys are really really smart.  I was totally lost!!!
Never stop Learning, Never stop Earning!!
哲人無憂,智者常樂。並不是因為所愛的一切他都擁有了,而是所擁有的一切他都愛。