summaryrefslogtreecommitdiff
path: root/prolog/problems/sorting/sins_3
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/problems/sorting/sins_3')
-rw-r--r--prolog/problems/sorting/sins_3/common.py14
-rw-r--r--prolog/problems/sorting/sins_3/en.py14
2 files changed, 28 insertions, 0 deletions
diff --git a/prolog/problems/sorting/sins_3/common.py b/prolog/problems/sorting/sins_3/common.py
new file mode 100644
index 0000000..8ebfee4
--- /dev/null
+++ b/prolog/problems/sorting/sins_3/common.py
@@ -0,0 +1,14 @@
+id = 122
+group = 'sorting'
+number = 29
+visible = True
+facts = None
+
+solution = '''\
+sins(X, [], [X]).
+sins(X, [Y|T], [X,Y|T]) :-
+ X =< Y.
+sins(X, [Y|T], [Y|L]) :-
+ X > Y,
+ sins(X, T, L).
+'''
diff --git a/prolog/problems/sorting/sins_3/en.py b/prolog/problems/sorting/sins_3/en.py
new file mode 100644
index 0000000..684a619
--- /dev/null
+++ b/prolog/problems/sorting/sins_3/en.py
@@ -0,0 +1,14 @@
+id = 122
+name = 'sins/3'
+slug = 'insert an element at correct position into a sorted list'
+
+description = '''\
+<p><code>sins(X, SortedList, NewList)</code>: the list <code>NewList</code> is obtained by inserting <code>X</code> into <code>SortedList</code> at the correct position to preserve the non-decreasing order of elements.</p>
+<pre>
+ ?- sins(4, [1,2,3,5], L).
+ L = [1,2,3,4,5].
+ ?- sins(3, [1,2,3,4], L).
+ L = [1,2,3,3,4].
+</pre>'''
+
+hint = {}