问题
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:
- The diner who ordered the red snapper didn't have the bordeaux.
- Lynda paid less than the one who had the bordeaux.
- Neither the one who had the bordeaux nor the one who had the chianti was the person who paid $26.99.
- The diner who ordered the beef stir-fry had the chianti.
- The diner who ordered the citrus chicken paid 1 dollar less than the one who had the chianti.
- The diner who ordered the filet mignon paid less than the one who had the shiraz.
- Virginia was either the diner who ordered the beef stir-fry or the diner who ordered the red snapper.
- 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