Puzzle in Prolog

不羁岁月 提交于 2019-12-13 08:20:00

问题


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


回答1:


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 zebra-puzzle tag.



来源:https://stackoverflow.com/questions/27580472/puzzle-in-prolog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!