Różnice

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

Odnośnik do tego porównania

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 =====
 +<code prolog>
 +/*
 +   ​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
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/union_and_intersection.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0