From 95e2fe57f6e4639f6ae9f1fef368829d5090dbf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Tue, 18 Aug 2015 16:06:19 +0200 Subject: Exported all problems from the SQLite database into the new directory structure. --- prolog/problems/trees/deletebt_3/common.py | 17 +++++++++++++++++ prolog/problems/trees/deletebt_3/en.py | 14 ++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 prolog/problems/trees/deletebt_3/common.py create mode 100644 prolog/problems/trees/deletebt_3/en.py (limited to 'prolog/problems/trees/deletebt_3') diff --git a/prolog/problems/trees/deletebt_3/common.py b/prolog/problems/trees/deletebt_3/common.py new file mode 100644 index 0000000..76550f6 --- /dev/null +++ b/prolog/problems/trees/deletebt_3/common.py @@ -0,0 +1,17 @@ +id = 137 +group = 'trees' +number = 47 +visible = True +facts = None + +solution = '''\ +deleteBT(X, b(nil, X, nil), nil). +deleteBT(X, b(b(Ls, E, Rs), X, R), b(L, E, R)) :- + deleteBT(E, b(Ls, E, Rs), L). +deleteBT(X, b(L, X, b(Ls, E, Rs)), b(L, E, R)) :- + deleteBT(E, b(Ls, E, Rs), R). +deleteBT(X, b(L, E, R), b(L1, E, R)) :- + deleteBT(X, L, L1). +deleteBT(X, b(L, E, R), b(L, E, R1)) :- + deleteBT(X, R, R1). +''' diff --git a/prolog/problems/trees/deletebt_3/en.py b/prolog/problems/trees/deletebt_3/en.py new file mode 100644 index 0000000..557efaa --- /dev/null +++ b/prolog/problems/trees/deletebt_3/en.py @@ -0,0 +1,14 @@ +id = 137 +name = 'deleteBT/3' +slug = 'delete an element from a binary tree' + +description = '''\ +

deleteBT(X, T, NewT): the binary tree NewT is obtained from T by deleting one occurence of the element X. If X is not a leaf node, the root of one of its subtrees is moved up. Your code should generate all valid solutions.

+
+  ?- deleteBT(1, b(b(b(nil,4,nil),2,b(nil,6,nil)),1,b(nil,3,b(nil,5,nil))), T).
+    T = b(b(nil,4,b(nil,6,nil)),2,b(nil,3,b(nil,5,nil))) ;
+    T = b(b(b(nil,4,nil),6,nil),2,b(nil,3,b(nil,5,nil))) ;
+    T = b(b(b(nil,4,nil),2,b(nil,6,nil)),3,b(nil,5,nil)).
+
''' + +hint = {} -- cgit v1.2.1