skip to Main Content

This may be a rookie mistake, but I’m trying to solve this question:

Find the query to obtain the following answer using the findall predicate: Obtain a list of persons who work in a city other than the one where they live:

L = [suzy, paul].

This is the database:

city(ottawa,ontario).
city(toronto,ontario).
city(kingston,ontario).
city(gatineau,quebec).
city(montreal,quebec).

company(shopify,ottawa).
company(rossvideo,ottawa).
company(dium,gatineau).
company(uber,toronto).
company(deepmind,montreal).
company(google,toronto).

person(annie,gatineau).
person(paul,gatineau).
person(suzy,gatineau).
person(robert,gatineau).
person(tom,ottawa).
person(tim,kingston).
person(joe,montreal).
person(jane,ottawa).
person(marie,ottawa).
person(jack,toronto).
person(simon,toronto).

employee(annie,dium).
employee(tom,shopify).
employee(jane,shopify).
employee(marie,shopify).
employee(joe,deepmind).
employee(jack,google).
employee(simon,google).
employee(suzy,shopify).
employee(paul,rossvideo).
employee(marie,rossvideo).
employee(simon,uber).

Here is the predicate I tried to use to solve it:

worksIn(n, Y) :-
   employee(n, Comp),
   company(Comp, Y).

But it only returns false. Does anyone know how to fix it?

2

Answers


  1. when use variables, first letter must be uppercase.

    Login or Signup to reply.
  2. I did:

    worksIn(P):- person(P,CL), employee(P, CO), company(CO, CW), CL/=CW.
    

    so the final answer is:

    findall(P, worksIn(P), L).
    

    I’m not sure if we can add the “worksIn” thing in or not

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search