summaryrefslogtreecommitdiff
path: root/prolog/problems/trees/membert_2
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/problems/trees/membert_2')
-rw-r--r--prolog/problems/trees/membert_2/common.py18
-rw-r--r--prolog/problems/trees/membert_2/en.py14
2 files changed, 32 insertions, 0 deletions
diff --git a/prolog/problems/trees/membert_2/common.py b/prolog/problems/trees/membert_2/common.py
new file mode 100644
index 0000000..177309f
--- /dev/null
+++ b/prolog/problems/trees/membert_2/common.py
@@ -0,0 +1,18 @@
+id = 142
+group = 'trees'
+number = 49
+visible = True
+facts = None
+
+solution = '''\
+memb142(X, [X|_]).
+memb142(X, [_|T]) :-
+ memb142(X, T).
+
+memberT(X, Tree) :-
+ Tree =.. [t, X|_].
+memberT(X, Tree) :-
+ Tree =.. [t, _|SubTrees],
+ memb142(SubTree, SubTrees),
+ memberT(X, SubTree).
+'''
diff --git a/prolog/problems/trees/membert_2/en.py b/prolog/problems/trees/membert_2/en.py
new file mode 100644
index 0000000..a6fdffb
--- /dev/null
+++ b/prolog/problems/trees/membert_2/en.py
@@ -0,0 +1,14 @@
+id = 142
+name = 'memberT/2'
+slug = 'find elements in a tree'
+
+description = '''\
+<p><code>memberT(X, T)</code>: <code>X</code> is an element of the tree <code>T</code>. A tree node is represented with the structure <code>t(E, T1, T2...)</code>, where <code>E</code> is the node's value, followed by any number of subtrees. An empty tree is denoted by <code>nil</code>.</p>
+<pre>
+ ?- memberT(X, t(3, t(1), t(2))).
+ X = 3 ;
+ X = 1 ;
+ X = 2.
+</pre>'''
+
+hint = {}