summaryrefslogtreecommitdiff
path: root/prolog/problems/lists
diff options
context:
space:
mode:
authorMartin Možina <martin.mozina@fri.uni-lj.si>2015-12-28 10:23:46 +0100
committerMartin Možina <martin.mozina@fri.uni-lj.si>2015-12-28 10:23:46 +0100
commit165c7165bb2184c9c9e0576a074ba4f29052bf8f (patch)
tree9b86dbbd1d4c39b52bfd7f54cfb13c2354727a53 /prolog/problems/lists
parent4cdea335b0951e3c12dfb7b906f958d6b5be25c6 (diff)
parentc1bb0d56b2c0482c766d094c65fdf0fd9d1aa0ba (diff)
Merge branch 'master' of 192.168.15.97:codeq-problems
Conflicts: python/problems/functions/palindrome/sl.py python/problems/functions/palindromic_numbers/sl.py
Diffstat (limited to 'prolog/problems/lists')
-rw-r--r--prolog/problems/lists/common.py2
-rw-r--r--prolog/problems/lists/conc_3/common.py7
-rw-r--r--prolog/problems/lists/conc_3/sl.py15
-rw-r--r--prolog/problems/lists/count_3/common.py7
-rw-r--r--prolog/problems/lists/count_3/sl.py13
-rw-r--r--prolog/problems/lists/del_3/common.py7
-rw-r--r--prolog/problems/lists/del_3/sl.py20
-rw-r--r--prolog/problems/lists/divide_3/common.py7
-rw-r--r--prolog/problems/lists/divide_3/sl.py15
-rw-r--r--prolog/problems/lists/dup_2/common.py7
-rw-r--r--prolog/problems/lists/dup_2/sl.py15
-rw-r--r--prolog/problems/lists/evenlen_1_+_oddlen_1/common.py7
-rw-r--r--prolog/problems/lists/evenlen_1_+_oddlen_1/sl.py18
-rw-r--r--prolog/problems/lists/insert_3/common.py7
-rw-r--r--prolog/problems/lists/insert_3/sl.py15
-rw-r--r--prolog/problems/lists/len_2/common.py7
-rw-r--r--prolog/problems/lists/len_2/sl.py13
-rw-r--r--prolog/problems/lists/max_2/common.py7
-rw-r--r--prolog/problems/lists/max_2/sl.py15
-rw-r--r--prolog/problems/lists/memb_2/common.py7
-rw-r--r--prolog/problems/lists/memb_2/sl.py17
-rw-r--r--prolog/problems/lists/min_2/common.py7
-rw-r--r--prolog/problems/lists/min_2/sl.py15
-rw-r--r--prolog/problems/lists/palindrome_1/common.py7
-rw-r--r--prolog/problems/lists/palindrome_1/sl.py15
-rw-r--r--prolog/problems/lists/permute_2/common.py7
-rw-r--r--prolog/problems/lists/permute_2/sl.py18
-rw-r--r--prolog/problems/lists/rev_2/common.py7
-rw-r--r--prolog/problems/lists/rev_2/en.py4
-rw-r--r--prolog/problems/lists/rev_2/sl.py15
-rw-r--r--prolog/problems/lists/shiftleft_2/common.py7
-rw-r--r--prolog/problems/lists/shiftleft_2/sl.py13
-rw-r--r--prolog/problems/lists/shiftright_2/common.py7
-rw-r--r--prolog/problems/lists/shiftright_2/sl.py13
-rw-r--r--prolog/problems/lists/sublist_2/common.py7
-rw-r--r--prolog/problems/lists/sublist_2/sl.py19
-rw-r--r--prolog/problems/lists/sum_2/common.py7
-rw-r--r--prolog/problems/lists/sum_2/sl.py13
38 files changed, 317 insertions, 92 deletions
diff --git a/prolog/problems/lists/common.py b/prolog/problems/lists/common.py
index 4788fc4..e7dd0d7 100644
--- a/prolog/problems/lists/common.py
+++ b/prolog/problems/lists/common.py
@@ -1,2 +1,4 @@
id = 2
number = 2
+
+allowed_groups = ['lists']
diff --git a/prolog/problems/lists/conc_3/common.py b/prolog/problems/lists/conc_3/common.py
index 6efac47..ffd8f0f 100644
--- a/prolog/problems/lists/conc_3/common.py
+++ b/prolog/problems/lists/conc_3/common.py
@@ -26,14 +26,11 @@ test_cases = [
[{}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/conc_3/sl.py b/prolog/problems/lists/conc_3/sl.py
new file mode 100644
index 0000000..15e3163
--- /dev/null
+++ b/prolog/problems/lists/conc_3/sl.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+
+name = 'conc/3'
+slug = 'Združi dva seznama (konkatenacija)'
+
+description = '''\
+<p><code>conc(L1, L2, L)</code>: seznam <code>L</code> dobiš tako, da seznamu <code>L1</code> na konec dodaš elemente seznama <code>L2</code>.</p>
+<pre>
+ ?- conc([1,2], [3,4], X).
+ X = [1,2,3,4].
+ ?- conc(X, [], [1,2,3]).
+ X = [1,2,3].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/count_3/common.py b/prolog/problems/lists/count_3/common.py
index c257d66..7970240 100644
--- a/prolog/problems/lists/count_3/common.py
+++ b/prolog/problems/lists/count_3/common.py
@@ -30,14 +30,11 @@ test_cases = [
[{'X': '2'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/count_3/sl.py b/prolog/problems/lists/count_3/sl.py
new file mode 100644
index 0000000..15a4650
--- /dev/null
+++ b/prolog/problems/lists/count_3/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'count/3'
+slug = 'Preštej kolikokrat se element pojavi v seznamu'
+
+description = '''\
+<p><code>count(X, L, N)</code>: <code>N</code> je število kolikokrat se element <code>X</code> pojavi v seznamu <code>L</code>.</p>
+<pre>
+ ?- count(1, [1,2,1,3,1], N).
+ N = 3.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/del_3/common.py b/prolog/problems/lists/del_3/common.py
index 5e00f4d..d0e4a29 100644
--- a/prolog/problems/lists/del_3/common.py
+++ b/prolog/problems/lists/del_3/common.py
@@ -24,14 +24,11 @@ test_cases = [
[{'X': 'g', 'Y': 'u', 'Z': 'f'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/del_3/sl.py b/prolog/problems/lists/del_3/sl.py
new file mode 100644
index 0000000..49ab16f
--- /dev/null
+++ b/prolog/problems/lists/del_3/sl.py
@@ -0,0 +1,20 @@
+# coding=utf-8
+
+name = 'del/3'
+slug = 'Zbriši element iz seznama'
+
+description = '''\
+<p><code>del(X, L1, L2)</code>: seznam <code>L2</code> dobimo iz seznama <code>L1</code> tako da zbrišemo element <code>X</code>.</p>
+<pre>
+ ?- del(1, [1,2,3], L).
+ L = [2,3].
+ ?- del(2, [1,2,3,2,5], L).
+ L = [1,3,2,5] ;
+ L = [1,2,3,5].
+ ?- del(X, [1,2,3], L).
+ X = 1, L = [2,3] ;
+ X = 2, L = [1,3] ;
+ X = 3, L = [1,2].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/divide_3/common.py b/prolog/problems/lists/divide_3/common.py
index 83a8a9e..1f14d2f 100644
--- a/prolog/problems/lists/divide_3/common.py
+++ b/prolog/problems/lists/divide_3/common.py
@@ -29,14 +29,11 @@ test_cases = [
[{'A': '[t, l, q, e, y, r]'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/divide_3/sl.py b/prolog/problems/lists/divide_3/sl.py
new file mode 100644
index 0000000..ecf9a5a
--- /dev/null
+++ b/prolog/problems/lists/divide_3/sl.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+
+name = 'divide/3'
+slug = 'Razdeli dani seznam na dva podseznama (približno) enake velikosti'
+
+description = '''\
+<p><code>divide(L, L1, L2)</code>: seznam <code>L1</code> vsebuje elemente na lihih pozicijah v seznamu <code>L</code>, seznam <code>L2</code> pa elemente na sodih pozicijah v <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 = {}
diff --git a/prolog/problems/lists/dup_2/common.py b/prolog/problems/lists/dup_2/common.py
index cce5aef..66b9c64 100644
--- a/prolog/problems/lists/dup_2/common.py
+++ b/prolog/problems/lists/dup_2/common.py
@@ -26,14 +26,11 @@ test_cases = [
[{'X': '[k, f, f, g, a]'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/dup_2/sl.py b/prolog/problems/lists/dup_2/sl.py
new file mode 100644
index 0000000..fc974d8
--- /dev/null
+++ b/prolog/problems/lists/dup_2/sl.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+
+name = 'dup/2'
+slug = 'Podvoji vse elemente v seznamu'
+
+description = '''\
+<p><code>dup(L1, L2)</code>: seznam <code>L2</code> dobimo iz <code>L1</code> tako, da podvojimo vsak element.</p>
+<pre>
+ ?- dup([1,2], X).
+ X = [1,1,2,2].
+ ?- dup([1,2,3], X).
+ X = [1,1,2,2,3,3].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/evenlen_1_+_oddlen_1/common.py b/prolog/problems/lists/evenlen_1_+_oddlen_1/common.py
index 13d9bca..b683cf7 100644
--- a/prolog/problems/lists/evenlen_1_+_oddlen_1/common.py
+++ b/prolog/problems/lists/evenlen_1_+_oddlen_1/common.py
@@ -32,14 +32,11 @@ test_cases = [
[{}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/evenlen_1_+_oddlen_1/sl.py b/prolog/problems/lists/evenlen_1_+_oddlen_1/sl.py
new file mode 100644
index 0000000..1959877
--- /dev/null
+++ b/prolog/problems/lists/evenlen_1_+_oddlen_1/sl.py
@@ -0,0 +1,18 @@
+# coding=utf-8
+
+name = 'evenlen/1 + oddlen/1'
+slug = 'Brez aritmetike preveri, če je seznam sode ali lihe dolžine'
+
+description = '''\
+<p><code>evenlen(L)</code>: seznam <code>L</code> ima sodo število elementov.<br />
+<code>oddlen(L)</code>: seznam <code>L</code> ima liho število elementov.</p>
+<pre>
+ ?- oddlen([1,2,3,4,5]).
+ true.
+ ?- oddlen([1,2,3,4]).
+ false.
+ ?- evenlen([1,2,3,4]).
+ true.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/insert_3/common.py b/prolog/problems/lists/insert_3/common.py
index fe1fbb6..7d92726 100644
--- a/prolog/problems/lists/insert_3/common.py
+++ b/prolog/problems/lists/insert_3/common.py
@@ -26,14 +26,11 @@ test_cases = [
[{'A': 'c', 'X': 'i'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/insert_3/sl.py b/prolog/problems/lists/insert_3/sl.py
new file mode 100644
index 0000000..08ffced
--- /dev/null
+++ b/prolog/problems/lists/insert_3/sl.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+
+name = 'insert/3'
+slug = 'Vstavi element na poljubno mesto v seznamu'
+
+description = '''\
+<p><code>insert(X, L1, L2)</code>: seznam <code>L2</code> dobimo iz <code>L1</code> tako, da vstavimo element <code>X</code> na poljubno mesto. Predikat naj vrne vse možne rešitve, eno za drugo.</p>
+<pre>
+ ?- insert(1, [2,3], L).
+ L = [1,2,3] ;
+ L = [2,1,3] ;
+ L = [2,3,1].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/len_2/common.py b/prolog/problems/lists/len_2/common.py
index 94a05c5..538db56 100644
--- a/prolog/problems/lists/len_2/common.py
+++ b/prolog/problems/lists/len_2/common.py
@@ -25,14 +25,11 @@ test_cases = [
[{'X': '0'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/len_2/sl.py b/prolog/problems/lists/len_2/sl.py
new file mode 100644
index 0000000..5b9f05a
--- /dev/null
+++ b/prolog/problems/lists/len_2/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'len/2'
+slug = 'Izračunaj dolžino danega seznama'
+
+description = '''\
+<p><code>len(L, Len)</code>: <code>Len</code> je dolžina seznama <code>L</code>.</p>
+<pre>
+ ?- len([1,2,3], Len).
+ Len = 3.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/max_2/common.py b/prolog/problems/lists/max_2/common.py
index 1f8769a..6fd9a4d 100644
--- a/prolog/problems/lists/max_2/common.py
+++ b/prolog/problems/lists/max_2/common.py
@@ -29,14 +29,11 @@ test_cases = [
[{'X': '-22'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/max_2/sl.py b/prolog/problems/lists/max_2/sl.py
new file mode 100644
index 0000000..81c354b
--- /dev/null
+++ b/prolog/problems/lists/max_2/sl.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+
+name = 'max/2'
+slug = 'Poišči največji element v danem seznamu'
+
+description = '''\
+<p><code>max(L, Max)</code>: <code>Max</code> je največji element v seznamu <code>L</code>.</p>
+<pre>
+ ?- max([5,4,1,6], M).
+ M = 6.
+ ?- max([3,2,2], M).
+ M = 3.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/memb_2/common.py b/prolog/problems/lists/memb_2/common.py
index 30a6dfd..691471f 100644
--- a/prolog/problems/lists/memb_2/common.py
+++ b/prolog/problems/lists/memb_2/common.py
@@ -22,14 +22,11 @@ test_cases = [
[{'X': 'y'}, {'X': 'l'}, {'X': 'r'}, {'X': 'g'}, {'X': 'a'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/memb_2/sl.py b/prolog/problems/lists/memb_2/sl.py
new file mode 100644
index 0000000..540394b
--- /dev/null
+++ b/prolog/problems/lists/memb_2/sl.py
@@ -0,0 +1,17 @@
+# coding=utf-8
+
+name = 'memb/2'
+slug = 'Preveri (poišči), če je dani element v seznamu'
+
+description = '''\
+<p><code>memb(E, L)</code>: <code>E</code> je element seznama <code>L</code>.</p>
+<pre>
+ ?- memb(X, [1,2,3]).
+ X = 1 ;
+ X = 2 ;
+ X = 3.
+ ?- memb(1, [3,2,X]).
+ X = 1.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/min_2/common.py b/prolog/problems/lists/min_2/common.py
index fc505b7..65ce979 100644
--- a/prolog/problems/lists/min_2/common.py
+++ b/prolog/problems/lists/min_2/common.py
@@ -29,14 +29,11 @@ test_cases = [
[{'X': '-22'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/min_2/sl.py b/prolog/problems/lists/min_2/sl.py
new file mode 100644
index 0000000..6a5964b
--- /dev/null
+++ b/prolog/problems/lists/min_2/sl.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+
+name = 'min/2'
+slug = 'Poišči najmanjši element v danem seznamu'
+
+description = '''\
+<p><code>min(L, Min)</code>: <code>Min</code> je najmanjši element v seznamu <code>L</code>.</p>
+<pre>
+ ?- min([5,4,1,6], M).
+ M = 1.
+ ?- min([3,2,2], M).
+ M = 2.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/palindrome_1/common.py b/prolog/problems/lists/palindrome_1/common.py
index 044f7be..7050c8c 100644
--- a/prolog/problems/lists/palindrome_1/common.py
+++ b/prolog/problems/lists/palindrome_1/common.py
@@ -30,14 +30,11 @@ test_cases = [
[{'X': 'b'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/palindrome_1/sl.py b/prolog/problems/lists/palindrome_1/sl.py
new file mode 100644
index 0000000..04f1f59
--- /dev/null
+++ b/prolog/problems/lists/palindrome_1/sl.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+
+name = 'palindrome/1'
+slug = 'Preveri, če elementi seznama tvorijo palindrom'
+
+description = '''\
+<p><code>palindrome(L)</code>: Elementi seznama <code>L</code> se preberejo v istem vrstnem redu z začetka in s konca seznama.</p>
+<pre>
+ ?- palindrome([1,2,3,2,1]).
+ true.
+ ?- palindrome([1,2,3]).
+ false.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/permute_2/common.py b/prolog/problems/lists/permute_2/common.py
index 5ade0b5..162b018 100644
--- a/prolog/problems/lists/permute_2/common.py
+++ b/prolog/problems/lists/permute_2/common.py
@@ -28,14 +28,11 @@ test_cases = [
[{'X': '[[b, e, l], [b, l, e], [e, b, l], [e, l, b], [l, b, e], [l, e, b]]'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/permute_2/sl.py b/prolog/problems/lists/permute_2/sl.py
new file mode 100644
index 0000000..2c98340
--- /dev/null
+++ b/prolog/problems/lists/permute_2/sl.py
@@ -0,0 +1,18 @@
+# coding=utf-8
+
+name = 'permute/2'
+slug = 'Generiraj permutacije elementov v seznamu'
+
+description = '''\
+<p><code>permute(L1, L2)</code>: seznam <code>L2</code> je permutacija vrstnega reda elementov v seznamu <code>L1</code>.</p>
+<pre>
+ ?- permute([1,2,3], L).
+ L = [1,2,3] ;
+ L = [1,3,2] ;
+ L = [2,1,3] ;
+ L = [2,3,1] ;
+ L = [3,1,2] ;
+ L = [3,2,1].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/rev_2/common.py b/prolog/problems/lists/rev_2/common.py
index 2a16e27..f5e4d9c 100644
--- a/prolog/problems/lists/rev_2/common.py
+++ b/prolog/problems/lists/rev_2/common.py
@@ -28,14 +28,11 @@ test_cases = [
[{'X': '[d, d, c, k, s]'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/rev_2/en.py b/prolog/problems/lists/rev_2/en.py
index fe36ec5..7941f9e 100644
--- a/prolog/problems/lists/rev_2/en.py
+++ b/prolog/problems/lists/rev_2/en.py
@@ -6,10 +6,10 @@ slug = 'reverse a list'
description = '''\
<p><code>rev(L1, L2)</code>: the list <code>L2</code> is obtained from <code>L1</code> by reversing the order of the elements.</p>
<pre>
- ?- rev([], X).
- X = [].
?- rev([1,2,3], X).
X = [3,2,1].
+ ?- rev([], X).
+ X = [].
</pre>'''
hint = {}
diff --git a/prolog/problems/lists/rev_2/sl.py b/prolog/problems/lists/rev_2/sl.py
new file mode 100644
index 0000000..95ba8b7
--- /dev/null
+++ b/prolog/problems/lists/rev_2/sl.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+
+name = 'rev/2'
+slug = 'Obrni seznam'
+
+description = '''\
+<p><code>rev(L1, L2)</code>: seznam <code>L2</code> ima elemente v obratnem vrstnem redu kot seznam <code>L1</code>.</p>
+<pre>
+ ?- rev([1,2,3], X).
+ X = [3,2,1].
+ ?- rev([], X).
+ X = [].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/shiftleft_2/common.py b/prolog/problems/lists/shiftleft_2/common.py
index 8de545b..6f3576b 100644
--- a/prolog/problems/lists/shiftleft_2/common.py
+++ b/prolog/problems/lists/shiftleft_2/common.py
@@ -26,14 +26,11 @@ test_cases = [
[{'A': 'x', 'B': 'y', 'C': 'l', 'D': 'c', 'E': 'h'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/shiftleft_2/sl.py b/prolog/problems/lists/shiftleft_2/sl.py
new file mode 100644
index 0000000..44e726f
--- /dev/null
+++ b/prolog/problems/lists/shiftleft_2/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'shiftleft/2'
+slug = 'Premakni elemente seznama za eno mesto v levo'
+
+description = '''\
+<p><code>shiftleft(L1, L2)</code>: elemente v seznamu <code>L1</code> za eno mesto premaknemo v levo ("circular shift").</p>
+<pre>
+ ?- shiftleft([1,2,3,4,5], X).
+ X = [2,3,4,5,1].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/shiftright_2/common.py b/prolog/problems/lists/shiftright_2/common.py
index 205daa9..3084f9f 100644
--- a/prolog/problems/lists/shiftright_2/common.py
+++ b/prolog/problems/lists/shiftright_2/common.py
@@ -26,14 +26,11 @@ test_cases = [
[{'A': 'x', 'B': 'y', 'C': 'c', 'D': 'h', 'E': 'l'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/shiftright_2/sl.py b/prolog/problems/lists/shiftright_2/sl.py
new file mode 100644
index 0000000..9d84510
--- /dev/null
+++ b/prolog/problems/lists/shiftright_2/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'shiftright/2'
+slug = 'Premakni elemente seznama za eno mesto v desno'
+
+description = '''\
+<p><code>shiftright(L1, L2)</code>: elemente v seznamu <code>L1</code> za eno mesto premaknemo v desno ("circular shift").</p>
+<pre>
+ ?- shiftright([1,2,3,4,5], X).
+ X = [5,1,2,3,4].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/sublist_2/common.py b/prolog/problems/lists/sublist_2/common.py
index bcf3315..e2d8964 100644
--- a/prolog/problems/lists/sublist_2/common.py
+++ b/prolog/problems/lists/sublist_2/common.py
@@ -29,14 +29,11 @@ test_cases = [
[{'X': '[[], [a], [a, b], [a, b, c], [b], [b, c], [c]]'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/sublist_2/sl.py b/prolog/problems/lists/sublist_2/sl.py
new file mode 100644
index 0000000..27d9b54
--- /dev/null
+++ b/prolog/problems/lists/sublist_2/sl.py
@@ -0,0 +1,19 @@
+# coding=utf-8
+
+name = 'sublist/2'
+slug = 'Generiraj vse podsezname danega seznama'
+
+description = '''\
+<p><code>sublist(L, SL)</code>: <code>SL</code> je podseznam seznama <code>L</code>. Predikat naj vrne vse možne podsezname, enega po enega.</p>
+<pre>
+ ?- sublist([1,2,3], X).
+ X = [] ;
+ X = [1] ;
+ X = [1,2] ;
+ X = [1,2,3] ;
+ X = [2] ;
+ X = [2,3] ;
+ X = [3].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/lists/sum_2/common.py b/prolog/problems/lists/sum_2/common.py
index a849601..568cfca 100644
--- a/prolog/problems/lists/sum_2/common.py
+++ b/prolog/problems/lists/sum_2/common.py
@@ -25,14 +25,11 @@ test_cases = [
[{'X': '4'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems))
-
+def test(code, aux_code):
n_correct = 0
engine_id = None
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
if engine_id is not None and 'error' not in map(itemgetter(0), output):
# Engine successfully created, and no syntax error in program.
for query, answers in test_cases:
diff --git a/prolog/problems/lists/sum_2/sl.py b/prolog/problems/lists/sum_2/sl.py
new file mode 100644
index 0000000..0e1e6d6
--- /dev/null
+++ b/prolog/problems/lists/sum_2/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'sum/2'
+slug = 'Izračunaj vsoto elementov v seznamu'
+
+description = '''\
+<p><code>sum(L, Sum)</code>: <code>Sum</code> je vsota vseh elementov v seznamu <code>L</code>.</p>
+<pre>
+ ?- sum([1,2,3], Sum).
+ Sum = 6.
+</pre>'''
+
+hint = {}