Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. setIntersection([], [], []).
  2. setIntersection([], _, []).
  3.  
  4. setIntersection([X|Xs], Y, [Z|W]) :-
  5. keepDuplicates(X, Y, [Z|Zs]),
  6. setIntersection(Xs, Y, W).
  7.  
  8. keepDuplicates(_, [], []).
  9. keepDuplicates([], _, []).
  10. keepDuplicates([], [], []).
  11.  
  12. % Check if the head of the first list is not a match to the
  13. % first head of the second list
  14. keepDuplicates(G, [H|Hs], Line) :-
  15. G = H,
  16. keepDuplicates(G, Hs, Line).
  17.  
  18. % Check if the head of the first list
  19. % Does match to the head of the second list
  20. keepDuplicates(G, [G|Gs], [G|NewLine]) :-
  21. keepDuplicates(G, Gs, NewLine).
  22.  
  23. ?- L1=[3,4,5,6],L2=[5,1,0,2,4],findall(C, (member(C,L1),memberchk(C,L2)), I).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement