summaryrefslogtreecommitdiff
path: root/prolog/problems/sets/intersect_3
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/problems/sets/intersect_3')
-rw-r--r--prolog/problems/sets/intersect_3/common.py18
-rw-r--r--prolog/problems/sets/intersect_3/en.py12
2 files changed, 30 insertions, 0 deletions
diff --git a/prolog/problems/sets/intersect_3/common.py b/prolog/problems/sets/intersect_3/common.py
new file mode 100644
index 0000000..ffa4f89
--- /dev/null
+++ b/prolog/problems/sets/intersect_3/common.py
@@ -0,0 +1,18 @@
+id = 129
+group = 'sets'
+number = 36
+visible = True
+facts = None
+
+solution = '''\
+memb129(X, [X|_]).
+memb129(X, [_|T]) :-
+ memb129(X, T).
+
+intersect([], _, []).
+intersect([H|T], S2, [H|I]) :-
+ memb129(H, S2), !,
+ intersect(T, S2, I).
+intersect([_|T], S2, I):-
+ intersect(T, S2, I).
+'''
diff --git a/prolog/problems/sets/intersect_3/en.py b/prolog/problems/sets/intersect_3/en.py
new file mode 100644
index 0000000..b4296e4
--- /dev/null
+++ b/prolog/problems/sets/intersect_3/en.py
@@ -0,0 +1,12 @@
+id = 129
+name = 'intersect/3'
+slug = 'find the intersection of two sets'
+
+description = '''\
+<p><code>intersect(S1, S2, I)</code>: the list <code>I</code> contains every element that appears in both <code>S1</code> and <code>S2</code>, with no duplicates.</p>
+<pre>
+ ?- intersect([1,5,6,3,4,2], [8,1,5,9,4,3], I).
+ I = [1,5,3,4].
+</pre>'''
+
+hint = {}