Interpreters riddle in prolog

2019-09-19 01:15发布

问题:

Here's a riddle's info


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:

  1. No interpreter speak the language corresponding to his surname.
  2. No two interpreters speak the same two languages ​
  3. Each of the six languages is ​​spoken by exactly two interpreters.
  4. Spike speaks Dutch and German.
  5. There is an interpreter who speaks Dutch and Polish.
  6. Fran and Dudley speak four languages ​​(two each) that do not correspond to their surnames.
  7. Interpreters who have as surnames the languages ​​spoken by Dudley, speak French.
  8. There is no interpreter who can speak German and Polish.

What languages ​​are spoken by every interpreter?


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), .

I need help mostly with rules 2 and 7. Any help appreciated.