问题描述
这是一个谜语的信息
六位口译员:弗兰克(Fran French),杰拉尔丁(Geraldine German),达德利·荷兰(Dudley Dutch),斯派克(Spike)西班牙语,波莉(波兰)和罗马尼亚罗恩(Ronian).每个人都说两种语言,其中包括自己的姓氏,分别是法语(法语),德语(德语),荷兰语(荷兰),西班牙语(西班牙语),波兰语(波兰语)和罗马尼亚语(罗马尼亚语).适用以下条件:
Six interpreters: Fran French, Geraldine German, Dudley Dutch, Spike Spanish, Polly Polish and Romanian Ron. Everyone speaks two languages, among them indicating their surnames, namely French (French), Deutsch (German), Dutch (Dutch), Spanish (Spanish), Polish (Polish) and Romanian ( Romanian). The following applies:
- 没有口译员说与他姓氏对应的语言.
- 没有两个口译员说两种相同的语言
- 六种语言中的每一种都是由两个口译员说的.
- Spike讲荷兰语和德语.
- 有一名荷兰语和波兰语的口译员.
- Fran和Dudley讲四种与姓氏不符的语言.
- 以达德利所说的语言为姓的口译员会说法语.
- 没有会说德语和波兰语的口译员.
每个口译员说什么语言?
What languages are spoken by every interpreter?
这是我到目前为止所做的.规则1,4和8返回正确的结果.
This is what I've done until now. Rules 1,4 and 8 are returning right results.
interpreter(fran,french).
interpreter(geraldine,german).
interpreter(dudley,dutch).
interpreter(spike,spanish).
interpreter(polly,polish).
interpreter(ron,romanian).
language(french).
language(german).
language(dutch).
language(spanish).
language(polish).
language(romanian).
%rule 1 OK
rule1([X,Y,Z,W]):- interpreter(X,Y), language(Z), language(W),
not(Z=W;Y=Z;Y=W),
Z\=W, Z@<W.
%rule 2
%rule2([X,Y,Z,W]):- interpreter(X,Y), language(Z), language(W).
%interpreter(I2,S2), language(Z2), language(W2).
%not(X1=X2),
%((Z1=Z2) -> not(W1=W2)).
%rule 3
rule3([X,Y,Z,W]):- interpreter(X,Y), language(Z1), language(W),
interpreter(X,Y), language(Z1), language(W),
interpreter(X,Y), language(Z2), language(W),
not(Z1=Z2).
%rule 4 OK
rule4([X,Y,Z,W]):- (X=spike -> Z=dutch,W=german;Z=_,W=_).
%rule 5
rule5([X,Y,dutch,polish]).
%rule 6
rule6a([fran,french,Z,W]):- interpreter(X,Y), language(Z1), language(W),
not(Z=dutch).
rule6b([dudley,dutch,Z,W]):- interpreter(X,Y), language(Z1), language(W),
not(Z=french).
/*
%rule 7
rule7([dudley,dutch,Z,W]):- rule7a(X,Z,L1,french),
rule7b(X,Z,french,L2),
rule7c(X,W,L1,french),
rule7d(X,W,french,L2).
*/
%rule 8 OK
rule8([X,Y,Z,W]):- interpreter(X,Y), language(Z), language(W),
((Z=german)-> not(W=polish);Z=_,W=_).
solution(X):- rule1(X), rule2(X), rule3(X), rule4(X), rule5(X), rule6(X), rule7(X), rule8(X), .
我需要有关规则2和7的帮助.
I need help mostly with rules 2 and 7. Any help appreciated.
推荐答案
我试图解决这个难题此处
我发现这种在这类问题中施加约束的方式更加容易.
I find this way of putting constraints in problems like these easier.
:- use_rendering(table,
[header(h('Name','Surname','L1','L2'))]).
interpreters(Is) :-
length(Is,6),
member(h(fran,french,_,_), Is),
member(h(geraldine,german,_,_), Is),
member(h(dudley,dutch,_,_), Is),
member(h(spike,spanish,_,_), Is),
member(h(polly,polish,_,_), Is),
member(h(ron,romanian,_,_), Is),
member(h(_,_,french,_), Is),member(h(_,_,_,french), Is),
member(h(_,_,german,_), Is),member(h(_,_,_,german), Is),
member(h(_,_,dutch,_), Is),member(h(_,_,_,dutch), Is),
member(h(_,_,spanish,_), Is),member(h(_,_,_,spanish), Is),
member(h(_,_,polish,_), Is),member(h(_,_,_,polish), Is),
member(h(_,_,romanian,_), Is),member(h(_,_,_,romanian), Is),
\+member(h(_,X,X,_), Is),
\+member(h(_,Y,_,Y), Is),
(member(h(spike,spanish,dutch,german), Is);member(h(spike,spanish,german,dutch), Is)),
(member(h(_,_,dutch,polish), Is);member(h(_,_,polish,dutch), Is)),
member(h(fran,french,E,F), Is),member(h(dudley,dutch,G,H), Is),E \= G, F \= G, E \= H, F \= H,
member(h(dudley,dutch,I,J), Is), (member(h(_,I,_,french), Is);member(h(_,I,french,_), Is)), (member(h(_,J,_,french), Is);member(h(_,J,french,_), Is)),
\+member(h(_,_,german,polish), Is),
\+member(h(_,_,polish,german), Is),
\+member(h(_,_,K,K), Is).
其中一个输出是
这篇关于口译员在序言中困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!