Einstein's Riddle

Howard Brazee howard at brazee.net
Tue Mar 13 22:54:56 CET 2001


This is cross-posted.  Please tell us which language you are using.

Yoann Padioleau wrote:

> "Steve Graham" <js.graham at home.com> writes:
>
> > Who would be interested in using his/her brain (and his computer) to solve
> > the following?
> here it is:
>
> %----------------------------------------------------------------
> % a sicstus program
> :- use_module(library(clpfd)).
>
> relation(Unknown) :-
>         Unknown =
>         [[Color1, Nationality1, Drink1, Smoke1, Pet1]
>         ,[Color2, Nationality2, Drink2, Smoke2, Pet2]
>         ,[Color3, Nationality3, Drink3, Smoke3, Pet3]
>         ,[Color4, Nationality4, Drink4, Smoke4, Pet4]
>         ,[Color5, Nationality5, Drink5, Smoke5, Pet5]
>         ]
>         , Colors =        [Color1, Color2, Color3, Color4, Color5]
>         , Nationalities = [Nationality1, Nationality2, Nationality3, Nationality4, Nationality5]
>         , Drinks =        [Drink1, Drink2, Drink3, Drink4, Drink5]
>         , Smokes =        [Smoke1, Smoke2, Smoke3, Smoke4, Smoke5]
>         , Pets   =        [Pet1, Pet2, Pet3, Pet4, Pet5],
>
>         Red = 1, Green = 2, Yellow = 3, Blue = 4, White = 5,
>         Brit = 1, Sweed = 2, Dane = 3, Norvegian = 4, German = 5,
>         Tea = 1, Coffee = 2, Milk = 3, Beer = 4, Water = 5,
>         Pall_mall = 1, Dunhill = 2, Blends = 3, Bluemaster = 4, Prince = 5,
>         Dogs = 1, Birds = 2, Cats = 3, Fish = 4, Horse = 5,
>
>         domain([Color1, Nationality1, Drink1, Smoke1, Pet1
>                ,Color2, Nationality2, Drink2, Smoke2, Pet2
>                ,Color3, Nationality3, Drink3, Smoke3, Pet3
>                ,Color4, Nationality4, Drink4, Smoke4, Pet4
>                ,Color5, Nationality5, Drink5, Smoke5, Pet5], 1, 5)
>         , all_different(Colors)
>         , all_different(Nationalities)
>         , all_different(Drinks)
>         , all_different(Smokes)
>         , all_different(Pets)
>         ,
>
> % cant do the member, cos member need instantiated things!! and if enum and then test member
> %  we gain nothing cos always big search space, the labeling must be at the end !!
>
>          A1 in 1..5, element(A1, Nationalities, Brit),  element(A1,Colors,Red),
>          A2 in 1..5, element(A2, Nationalities, Sweed), element(A2,Pets, Dogs),
>          A3 in 1..5, element(A3, Nationalities, Dane),  element(A3,Drinks, Tea),
>          A4 in 1..5, element(A4, Colors,        Green),
>          A5 in 1..5, A5 #= A4+1, element(A5, Colors, White),
>          A6 in 1..5, element(A6, Colors, Green),        element(A6, Drinks, Coffee),
>          A7 in 1..5, element(A7, Smokes, Pall_mall),    element(A7, Pets,  Birds),
>          A8 in 1..5, element(A8, Colors, Yellow),       element(A8, Smokes, Dunhill),
>          element(3, Drinks, Milk),
>          element(1, Nationalities, Norvegian),
>          A9 in 1..5, element(A9, Smokes, Blends),
>          A10 in 1..5, ((A10 #= A9-1) #\/ (A10 #= A9+1)), element(A10, Pets, Cats),
>          A11 in 1..5, element(A11, Pets, Horse),
>          A12 in 1..5 , ((A12 #= A11-1) #\/ (A12 #= A11+1)), element(A12, Smokes, Dunhill),
>          A13 in 1..5, element(A13, Smokes, Bluemaster),  element(A13, Drinks, Beer),
>          A14 in 1..5, element(A14, Nationalities, German), element(A14, Smokes, Prince),
>          A15 in 1..5, element(A15, Nationalities, Norvegian),
>          A16 in 1..5 , ((A16 #= A15-1) #\/ (A16 #= A15+1)), element(A16, Colors, Blue),
>          A17 in 1..5, element(A17, Smokes, Blends),
>          A18 in 1..5 , ((A18 #= A17-1) #\/ (A18 #= A17+1)), element(A18, Drinks, Water),
>
>         labeling([],
>                  [Color1, Nationality1, Drink1, Smoke1, Pet1
>                  ,Color2, Nationality2, Drink2, Smoke2, Pet2
>                  ,Color3, Nationality3, Drink3, Smoke3, Pet3
>                  ,Color4, Nationality4, Drink4, Smoke4, Pet4
>                  ,Color5, Nationality5, Drink5, Smoke5, Pet5
>                  , A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18
>                  ]).
>
> %relation(X).
> %  X = [[3,4,5,2,3],[4,3,1,3,5],[1,1,3,1,2],[2,5,2,5,4],[5,2,4,4,1]] ? ; corresponding to
> %  [Yellow, Norvegian, Water, Dunhill, Cats]
> %  [Blue,   Dane,       Tea,  Blends, Horse]
> %  [Red,    Brit,      Milk,  Pall_mall, Birds]
> %  [Green,  German,  Coffee,  Prince,    Fish]
> %  [White,  Sweed,   Beer,  Bluemaster,  Dogs]
>
> %----------------------------------------------------------------
>
> >
> >
> > Steve Graham
> >
> > ===
> >
> > Einstein's Riddle
> >
> > Albert Einstein wrote this riddle this century [ed. 20th century].  He said
> > 98% of the world could not solve it.
> >
> > There are 5 houses in 5 different colors.  In each house lives a person with
> > a different nationality.  The 5 owners drink a certain type of beverage,
> > smoke a certain brand of cigar, and keep a certain pet.  No owners
> > have the same pet, smoke the same brand of cigar or drink the same beverage.
> >
> > The question is: "Who owns the fish?"
> >
> > Hints:
> >
> > The Brit lives in the red house.
> >
> > The Sweed keeps dogs as pets.
> >
> > The Dane drinks tea.
> >
> > The green house is on the left of the white house.
> >
> > The green house's owner drinks coffee.
> >
> > The person who smokes Pall Mall rears birds.
> >
> > The owner of the yellow house smokes Dunhill.
> >
> > The man living in the center house drinks milk.
> >
> > The Norwegian lives in the first house.
> >
> > The man who smokes Blends lives next to the one who keeps cats.
> >
> > The man who keeps the horse lives next to the man who smokes Dunhill.
> >
> > The owner who smokes Bluemasters drinks beer.
> >
> > The German smokes Prince.
> >
> > The Norwegian lives next to the blue house.
> >
> > The man who smokes Blends has a neighbor who drinks water.
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
> --
> Yoann  Padioleau,  INSA de Rennes, France,   http://www.irisa.fr/prive/padiolea
> Opinions expressed here are only mine. Je n'écris qu'à titre personnel.
> **____   Get Free. Be Smart.  Simply use Linux and Free Software.   ____**




More information about the Python-list mailing list