diff options
author | Aleš Smodiš <aless@guru.si> | 2015-08-18 16:06:19 +0200 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-08-18 16:06:19 +0200 |
commit | 95e2fe57f6e4639f6ae9f1fef368829d5090dbf6 (patch) | |
tree | 462ba05eb0c4732ca1c97739548801258bf47b40 /prolog/problems/sets/intersect_3 |
Exported all problems from the SQLite database into the new directory structure.
Diffstat (limited to 'prolog/problems/sets/intersect_3')
-rw-r--r-- | prolog/problems/sets/intersect_3/common.py | 18 | ||||
-rw-r--r-- | prolog/problems/sets/intersect_3/en.py | 12 |
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 = {} |