这是一个谜语
六名翻译:Fran French,Geraldine German,Dudley Dutch,Spike Spanish,Polly Polish和Romanian Ron。每个人都会说两种语言,其中包括法语(法语),德语(德语),荷兰语(荷兰语),西班牙语(西班牙语),波兰语(波兰语)和罗马尼亚语(罗马尼亚语)。以下适用:
每位口译员使用哪种语言?
这是我迄今为止所做的。规则1,4和8正在返回正确的结果。
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.任何帮助都会受到赞赏。
答案 0 :(得分:0)
我试图解决这个难题here
我发现这种在这类问题中施加约束的方式更加容易。
:- 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).
输出之一是