summaryrefslogtreecommitdiff
path: root/prolog/problems/trees/insertbt_3
diff options
context:
space:
mode:
authorAleš Smodiš <aless@guru.si>2015-08-18 16:06:19 +0200
committerAleš Smodiš <aless@guru.si>2015-08-18 16:06:19 +0200
commit95e2fe57f6e4639f6ae9f1fef368829d5090dbf6 (patch)
tree462ba05eb0c4732ca1c97739548801258bf47b40 /prolog/problems/trees/insertbt_3
Exported all problems from the SQLite database into the new directory structure.
Diffstat (limited to 'prolog/problems/trees/insertbt_3')
-rw-r--r--prolog/problems/trees/insertbt_3/common.py20
-rw-r--r--prolog/problems/trees/insertbt_3/en.py15
2 files changed, 35 insertions, 0 deletions
diff --git a/prolog/problems/trees/insertbt_3/common.py b/prolog/problems/trees/insertbt_3/common.py
new file mode 100644
index 0000000..efbfb7d
--- /dev/null
+++ b/prolog/problems/trees/insertbt_3/common.py
@@ -0,0 +1,20 @@
+id = 138
+group = 'trees'
+number = 48
+visible = True
+facts = None
+
+solution = '''\
+deleteBT138(X, b(nil, X, nil), nil).
+deleteBT138(X, b(b(Ls, E, Rs), X, R), b(L, E, R)) :-
+ deleteBT138(E, b(Ls, E, Rs), L).
+deleteBT138(X, b(L, X, b(Ls, E, Rs)), b(L, E, R)) :-
+ deleteBT138(E, b(Ls, E, Rs), R).
+deleteBT138(X, b(L, E, R), b(L1, E, R)) :-
+ deleteBT138(X, L, L1).
+deleteBT138(X, b(L, E, R), b(L, E, R1)) :-
+ deleteBT138(X, R, R1).
+
+insertBT(X, T, NewT) :-
+ deleteBT138(X, NewT, T).
+'''
diff --git a/prolog/problems/trees/insertbt_3/en.py b/prolog/problems/trees/insertbt_3/en.py
new file mode 100644
index 0000000..202df0a
--- /dev/null
+++ b/prolog/problems/trees/insertbt_3/en.py
@@ -0,0 +1,15 @@
+id = 138
+name = 'insertBT/3'
+slug = 'insert an element into a binary tree'
+
+description = '''\
+<p><code>insertBT(X, T, NewT)</code>: the binary tree <code>NewT</code> is obtained from <code>T</code> by inserting the element <code>X</code> at a certain position. This is the opposite of the predicate <code>deleteBT/3</code>. Your code should generate all valid solutions.</p>
+<pre>
+ ?- insertBT(2, b(nil,1,nil), T).
+ T = b(b(nil,1,nil),2,nil) ;
+ T = b(nil,2,b(nil,1,nil)) ;
+ T = b(b(nil,2,nil),1,nil) ;
+ T = b(nil,1,b(nil,2,nil)).
+</pre>'''
+
+hint = {}