益智在序言中 [英] Puzzle in Prolog
问题描述
任何人都可以解决这个难题:
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.
名字:Lynda,Nick,Robin,Virginia 葡萄酒:波尔多,基安蒂,梅鹿lot,设拉子 主菜:牛肉炒,柑橘鸡,菲力牛排,红鲷鱼 价格:$ 24.99,$ 25.99,$ 26.99,$ 27.99
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
线索:
- 订购红鲷鱼的晚餐没有波尔多酒.
- 琳达(Lynda)的价格比波尔多葡萄酒的价格低.
- 拥有波尔多酒的人和拥有基安蒂酒的人都不是支付26.99美元的人.
- 点了份牛肉炒饭的小伙子吃了基安蒂.
- 订购柑桔鸡肉的餐馆的客人,比订购基安蒂鸡肉的餐馆的客人少付1美元.
- 点了菲力牛排的小伙子付的钱比带设拉子的那位小.
- 弗吉尼亚州要么是点菜的人,要么是点菜牛snap的人,要么是点菜的红鲷鱼.
- 拥有美乐的人比罗宾少花了1美元.
来源:
推荐答案
弄清楚每个人的名字,葡萄酒,主菜和价格
Figure out the first name, wine, entree, and price for each person
因此我们将每个人表示为4元复合词p(Name,Wine,Entree,Price)
.似乎也有四个.
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.
请在的问题上咨询问答斑马拼图标签.
这篇关于益智在序言中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!