# Różnice

Różnice między wybraną wersją a wersją aktualną.

 — pl:prolog:pllib:union_and_intersection [2019/06/27 15:50] (aktualna) Linia 1: Linia 1: + ====== Union and intersection ====== + {{tag>​math recursion}} + ===== Description ===== + Finding the union and intersection of two lists + + **Source**: ​ The Art of Prolog + ===== Download ===== + Program source code: {{union_and_intersection.pl}} + ===== Listing ===== + + /* + ​union_intersect(Xs,​Ys,​Us,​Is) :- + Us and Is are the union and intersection,​ respectively,​ of the + elements in Xs and Ys.  ​ + */ + + union_intersect([X|Xs],​Ys,​Us,​[X|Is]) :- + member(X,​Ys),​ union_intersect(Xs,​Ys,​Us,​Is). + union_intersect([X|Xs],​Ys,​[X|Us],​Is) :- + nonmember(X,​Ys),​ union_intersect(Xs,​Ys,​Us,​Is). + union_intersect([],​Ys,​Ys,​[]). + + %  Program 13.3    Finding the union and intersection of two lists + ​ + ===== Comments =====
pl/prolog/pllib/union_and_intersection.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)