1

I have interpreters and languages.

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

and the rule: No interpreters speak the same language.

Any help?

1 Answers1

0

One way to approach this is to first check if any two interpreters speak the same language, and then check if the negation of that rule is true.

rule2 :- not(nrule2(X, Y)).
nrule2(X, Y) :- interpreter(X, L1), interpreter(Y, L2), X \= Y, L1 = L2.

rule2 is only true above if no two interpreters speak the same language.

Randy Hickey
  • 193
  • 4
  • I'm sorry, but I forgot to mention than the second input in "interpreter" is their surname and NOT the language they speak. I'll edit and remove their surnames – Nikos Kiriakakis Apr 24 '17 at 18:44
  • If you remove the language spoken from the predicate, then how would one determine which language the interpreter speaks? There has to be some way to link the interpreter to a language. – Randy Hickey Apr 24 '17 at 18:57
  • I understand what you're saying. This is only part of a problem, which I posted and didn't get any solution. This is the whole image: http://stackoverflow.com/questions/43500776/interpreters-riddle-in-prolog – Nikos Kiriakakis Apr 24 '17 at 19:11
  • It looks like you have structured your rule predicates to accept one list [X,Y,Z,W] where X, Y correspond to names and Z,W correspond to languages. But based on the problem, what you want as a solution is a list of these lists (i.e. a list of people and the languages they speak). So you might want to restructure your rules to accept a list of lists and make sure that each list within that list adheres to the rule. – Randy Hickey Apr 24 '17 at 20:00
  • Ok, I'll try that. And since your first answer was correct for what I asked before my edit, I'll re-edit and accept your answer as correct. Thanks – Nikos Kiriakakis Apr 24 '17 at 21:06