Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Anybody solve this Puzzle :

Figure out the first name, wine, entree, and price for each person using the clues given. Below are all categories and options used in this puzzle.

First names: Lynda, Nick, Robin, Virginia Wines: bordeaux, chianti, merlot, shiraz Entrees: beef stir-fry, citrus chicken, filet mignon, red snapper Prices: $24.99, $25.99, $26.99, $27.99

Clues:

  1. The diner who ordered the red snapper didn't have the bordeaux.
  2. Lynda paid less than the one who had the bordeaux.
  3. Neither the one who had the bordeaux nor the one who had the chianti was the person who paid $26.99.
  4. The diner who ordered the beef stir-fry had the chianti.
  5. The diner who ordered the citrus chicken paid 1 dollar less than the one who had the chianti.
  6. The diner who ordered the filet mignon paid less than the one who had the shiraz.
  7. Virginia was either the diner who ordered the beef stir-fry or the diner who ordered the red snapper.
  8. The one who had the merlot paid 1 dollar less than Robin.

SOURCE:

logic-puzzles.org

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
210 views
Welcome To Ask or Share your Answers For Others

1 Answer

Figure out the first name, wine, entree, and price for each person

so we represent each person as 4-ary compound term, p(Name,Wine,Entree,Price). There seem to be four of them, too.

Then we just write down what we are told:

wine_and_dine(People):-
  length(People,4),
  Ordered1 = p(_,W1,red_snapper,_),   
             member(Ordered1, People),
             % W1 = bordeaux, but delay writing this down 
             %                 until it is defined some more
             % or use freeze/2 in SWI:
             freeze( W1, W1 = bordeaux),
  Lynda2 = p(lynda,_,_,PL2), 
             Had2 = p(_,bordeaux,_,PB2),
             member(Lynda2, People),
             member(Had2, People),
             % PL2 < PB2,     % check this only when they are known; or
             freeze(PL2, freeze(PB2, PL2 < PB2)),
  .... etc.

do consult the Q&A on the tag.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...