0
votes

I need to see if there are three people such that at least two are from the group g1. I wrote:

ingroup(person1, g1).
ingroup(person2, g1).
ingroup(person3, g1).
ingroup(person4, g2).
ingroup(person5, g2).
test_ok :- ingroup(X,g1),ingroup(Y,g1), ingroup(Z,G), diff(X,Y,Z).
diff(X,Y,Z) :- X =\= Y, X =\= Z, Y =\= Z.

This gives the following error in SWI Prolog:

68 ?- test_ok.
ERROR: =\=/2: Arithmetic: `person1/0' is not a function.

Where am I going wrong?

1
OT: your code is very expensive... lookout some cheaper alternative... - CapelliC

1 Answers

4
votes

You're using an arithmetic comparison operator but person1 is an atom. Hence the error message. Try to used instead the term comparison operators such as (\==)/2. See your Prolog system documentation for details.