summaryrefslogtreecommitdiff
path: root/prolog/problems/lists/divide_3
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/problems/lists/divide_3')
-rw-r--r--prolog/problems/lists/divide_3/common.py12
-rw-r--r--prolog/problems/lists/divide_3/en.py14
2 files changed, 26 insertions, 0 deletions
diff --git a/prolog/problems/lists/divide_3/common.py b/prolog/problems/lists/divide_3/common.py
new file mode 100644
index 0000000..901d2f4
--- /dev/null
+++ b/prolog/problems/lists/divide_3/common.py
@@ -0,0 +1,12 @@
+id = 115
+group = 'lists'
+number = 22
+visible = True
+facts = None
+
+solution = '''\
+divide([], [], []).
+divide([X], [X], []).
+divide([H1,H2|T], [H1|L1], [H2|L2]) :-
+ divide(T, L1, L2).
+'''
diff --git a/prolog/problems/lists/divide_3/en.py b/prolog/problems/lists/divide_3/en.py
new file mode 100644
index 0000000..1a8d94e
--- /dev/null
+++ b/prolog/problems/lists/divide_3/en.py
@@ -0,0 +1,14 @@
+id = 115
+name = 'divide/3'
+slug = 'split a list into parts of roughly equal length'
+
+description = '''\
+<p><code>divide(L, L1, L2)</code>: the list <code>L1</code> contains elements at odd positions in <code>L</code>, and the list <code>L2</code> contains the elements at even positions in <code>L</code>.</p>
+<pre>
+ ?- divide([a,b,c,d,e,f,g], X, Y).
+ X = [a,c,e,g], Y = [b,d,f].
+ ?- divide([a,b,c,d,e,f], X, Y).
+ X = [a,c,e], Y = [b,d,f].
+</pre>'''
+
+hint = {}