益智在序言中 [英] Puzzle in Prolog

查看:83
本文介绍了益智在序言中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解决这个难题:

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

线索:

  1. 订购红鲷鱼的晚餐没有波尔多酒.
  2. 琳达(Lynda)的价格比波尔多葡萄酒的价格低.
  3. 拥有波尔多酒的人和拥有基安蒂酒的人都不是支付26.99美元的人.
  4. 点了份牛肉炒饭的小伙子吃了基安蒂.
  5. 订购柑桔鸡肉的餐馆的客人,比订购基安蒂鸡肉的餐馆的客人少付1美元.
  6. 点了菲力牛排的小伙子付的钱比带设拉子的那位小.
  7. 弗吉尼亚州要么是点菜的人,要么是点菜牛snap的人,要么是点菜的红鲷鱼.
  8. 拥有美乐的人比罗宾少花了1美元.

来源:

logic-puzzles.org

推荐答案

弄清楚每个人的名字,葡萄酒,主菜和价格

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆