I recently started learning prolog in university(1 week in) and have a question!

So for example.

intersect([a,b,d], [b,c,a,l], L).

should output:

L=[a,b] or L=[b,a].

I've been trying for hours yet can't get it to work. I want to figure it out on my own, but I could really use some pointers in the right directions.

BTW: I'm only allowed to use member/2 as a built-in. I'm not allowed to use any other built-in predicates.

1

There are 1 answers

0
excitedWithin On
inters([H1|T1],L2,[H1|L]):-
                        member(H1,L2),
                        inters(T1,L2,L).
inters([H1|T1],L2,L3):-
                        not(member(H1,L2)),
                        inters(T1,L2,L3).
inters([],_,[]).

and you can do your question: ?- inters([a,b,d],[b,c,a,l],L). as you see i 've removed all the spaces that you had in between the parameters.