summaryrefslogtreecommitdiff
path: root/prolog
diff options
context:
space:
mode:
Diffstat (limited to 'prolog')
-rw-r--r--prolog/common.py6
-rw-r--r--prolog/problems/clp_fd/common.py2
-rw-r--r--prolog/problems/clp_fd/gcd_3/common.py41
-rw-r--r--prolog/problems/clp_fd/gcd_3/sl.py14
-rw-r--r--prolog/problems/clp_fd/magic_1/common.py38
-rw-r--r--prolog/problems/clp_fd/magic_1/sl.py14
-rw-r--r--prolog/problems/clp_fd/puzzle_abc_3/common.py33
-rw-r--r--prolog/problems/clp_fd/puzzle_abc_3/sl.py10
-rw-r--r--prolog/problems/clp_fd/puzzle_beth_1/common.py33
-rw-r--r--prolog/problems/clp_fd/puzzle_beth_1/sl.py11
-rw-r--r--prolog/problems/clp_fd/puzzle_momson_2/common.py35
-rw-r--r--prolog/problems/clp_fd/puzzle_momson_2/sl.py10
-rw-r--r--prolog/problems/clp_fd/puzzle_ratio_2/common.py33
-rw-r--r--prolog/problems/clp_fd/puzzle_ratio_2/sl.py10
-rw-r--r--prolog/problems/clp_fd/tobase_3/common.py43
-rw-r--r--prolog/problems/clp_fd/tobase_3/sl.py17
-rw-r--r--prolog/problems/clp_r/common.py2
-rw-r--r--prolog/problems/dcg/ab_2/sl.py11
-rw-r--r--prolog/problems/dcg/common.py2
-rw-r--r--prolog/problems/dcg/digit_2/sl.py9
-rw-r--r--prolog/problems/dcg/expr_2/sl.py11
-rw-r--r--prolog/problems/dcg/expr_3/sl.py15
-rw-r--r--prolog/problems/dcg/flower_2/sl.py11
-rw-r--r--prolog/problems/dcg/number_2/sl.py10
-rw-r--r--prolog/problems/dcg/number_3/sl.py14
-rw-r--r--prolog/problems/dcg/number_proper_2/sl.py10
-rw-r--r--prolog/problems/dcg/paren_2/sl.py11
-rw-r--r--prolog/problems/dcg/paren_3/sl.py14
-rw-r--r--prolog/problems/denotational_semantics/algol_3/common.py2
-rw-r--r--prolog/problems/denotational_semantics/algol_for_3/common.py2
-rw-r--r--prolog/problems/denotational_semantics/algol_if_3/common.py2
-rw-r--r--prolog/problems/denotational_semantics/common.py2
-rw-r--r--prolog/problems/denotational_semantics/prog_8puzzle_2/common.py2
-rw-r--r--prolog/problems/denotational_semantics/prog_8puzzle_3/common.py2
-rw-r--r--prolog/problems/denotational_semantics/prog_listswap_2/common.py2
-rw-r--r--prolog/problems/denotational_semantics/prog_listswap_3/common.py2
-rw-r--r--prolog/problems/family_relations/ancestor_2/common.py8
-rw-r--r--prolog/problems/family_relations/aunt_2/common.py8
-rw-r--r--prolog/problems/family_relations/brother_2/common.py8
-rw-r--r--prolog/problems/family_relations/common.py2
-rw-r--r--prolog/problems/family_relations/connected_3/common.py10
-rw-r--r--prolog/problems/family_relations/cousin_2/common.py8
-rw-r--r--prolog/problems/family_relations/descendant_2/common.py8
-rw-r--r--prolog/problems/family_relations/father_2/common.py8
-rw-r--r--prolog/problems/family_relations/grandparent_2/common.py8
-rw-r--r--prolog/problems/family_relations/mother_2/common.py8
-rw-r--r--prolog/problems/family_relations/sister_2/common.py8
-rw-r--r--prolog/problems/license_plates/checklicenseplate_3/common.py41
-rw-r--r--prolog/problems/license_plates/checklicenseplate_3/sl.py18
-rw-r--r--prolog/problems/license_plates/common.py2
-rw-r--r--prolog/problems/license_plates/firstminus_2/common.py33
-rw-r--r--prolog/problems/license_plates/firstminus_2/sl.py14
-rw-r--r--prolog/problems/license_plates/genexp_2/common.py42
-rw-r--r--prolog/problems/license_plates/genexp_2/sl.py19
-rw-r--r--prolog/problems/license_plates/getdigits_2/common.py35
-rw-r--r--prolog/problems/license_plates/getdigits_2/sl.py13
-rw-r--r--prolog/problems/license_plates/joindigits_2/common.py34
-rw-r--r--prolog/problems/license_plates/joindigits_2/sl.py16
-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
-rw-r--r--prolog/problems/old_exams/common.py2
-rw-r--r--prolog/problems/other/common.py2
-rw-r--r--prolog/problems/sets/common.py2
-rw-r--r--prolog/problems/sets/diff_3/common.py41
-rw-r--r--prolog/problems/sets/diff_3/sl.py13
-rw-r--r--prolog/problems/sets/intersect_3/common.py41
-rw-r--r--prolog/problems/sets/intersect_3/sl.py13
-rw-r--r--prolog/problems/sets/is_subset_2/common.py37
-rw-r--r--prolog/problems/sets/is_subset_2/sl.py15
-rw-r--r--prolog/problems/sets/is_superset_2/common.py37
-rw-r--r--prolog/problems/sets/is_superset_2/sl.py15
-rw-r--r--prolog/problems/sets/powerset_2/common.py35
-rw-r--r--prolog/problems/sets/powerset_2/sl.py13
-rw-r--r--prolog/problems/sets/subset_2/common.py51
-rw-r--r--prolog/problems/sets/subset_2/sl.py20
-rw-r--r--prolog/problems/sets/union_3/common.py11
-rw-r--r--prolog/problems/sets/union_3/sl.py13
-rw-r--r--prolog/problems/sorting/common.py2
-rw-r--r--prolog/problems/sorting/is_sorted_1/common.py43
-rw-r--r--prolog/problems/sorting/is_sorted_1/sl.py15
-rw-r--r--prolog/problems/sorting/isort_2/common.py37
-rw-r--r--prolog/problems/sorting/isort_2/sl.py13
-rw-r--r--prolog/problems/sorting/pivoting_4/common.py37
-rw-r--r--prolog/problems/sorting/pivoting_4/sl.py13
-rw-r--r--prolog/problems/sorting/quick_sort_2/common.py37
-rw-r--r--prolog/problems/sorting/quick_sort_2/sl.py13
-rw-r--r--prolog/problems/sorting/sins_3/common.py39
-rw-r--r--prolog/problems/sorting/sins_3/sl.py15
-rw-r--r--prolog/problems/sorting/slowest_sort_ever_2/common.py37
-rw-r--r--prolog/problems/sorting/slowest_sort_ever_2/sl.py13
-rw-r--r--prolog/problems/trees/common.py2
-rw-r--r--prolog/problems/trees/deletebt_3/common.py2
-rw-r--r--prolog/problems/trees/depthbt_2/common.py2
-rw-r--r--prolog/problems/trees/insertbt_3/common.py2
-rw-r--r--prolog/problems/trees/maxt_2/common.py2
-rw-r--r--prolog/problems/trees/memberbt_2/common.py2
-rw-r--r--prolog/problems/trees/membert_2/common.py2
-rw-r--r--prolog/problems/trees/mirrorbt_2/common.py2
-rw-r--r--prolog/problems/trees/numberbt_2/common.py2
-rw-r--r--prolog/problems/trees/tolistbt_2/common.py2
-rw-r--r--prolog/sl.py16
137 files changed, 1779 insertions, 178 deletions
diff --git a/prolog/common.py b/prolog/common.py
index 2dab1c3..1c83fee 100644
--- a/prolog/common.py
+++ b/prolog/common.py
@@ -2,7 +2,7 @@
import operator
import prolog.engine
-from server.hints import Hint
+from server.hints import Hint, HintPopup
id = 1
@@ -12,6 +12,10 @@ hint_type = {
'system_error': Hint('system_error'),
'test_results': Hint('test_results'),
'syntax_error': Hint('syntax_error'),
+ 'monkey_main': Hint('monkey_main'),
+ 'monkey_change': HintPopup('monkey_change', style='change'),
+ 'monkey_insert': HintPopup('monkey_insert', style='insert'),
+ 'monkey_remove': HintPopup('monkey_remove', style='remove'),
}
def hint(program, solved_problems):
diff --git a/prolog/problems/clp_fd/common.py b/prolog/problems/clp_fd/common.py
index 3b1f9cf..845ed8b 100644
--- a/prolog/problems/clp_fd/common.py
+++ b/prolog/problems/clp_fd/common.py
@@ -1,2 +1,4 @@
id = 8
number = 7
+
+allowed_groups = ['lists']
diff --git a/prolog/problems/clp_fd/gcd_3/common.py b/prolog/problems/clp_fd/gcd_3/common.py
index 7cd6623..f24e0bb 100644
--- a/prolog/problems/clp_fd/gcd_3/common.py
+++ b/prolog/problems/clp_fd/gcd_3/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 149
number = 61
visible = True
@@ -15,3 +19,40 @@ gcd(X, Y, GCD):-
cd(X, Y, GCD),
\+ ( cd(X, Y, CD), CD > GCD ).
'''
+
+test_cases = [
+ ('gcd(1, 1, X)',
+ [{'X': '1'}]),
+ ('gcd(12, 8, X)',
+ [{'X': '4'}]),
+ ('gcd(18, 36, X)',
+ [{'X': '18'}]),
+ ('gcd(21, 14, X)',
+ [{'X': '7'}]),
+ ('gcd(10, 22, X)',
+ [{'X': '2'}]),
+ ('gcd(66, 60, X)',
+ [{'X': '6'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/clp_fd/gcd_3/sl.py b/prolog/problems/clp_fd/gcd_3/sl.py
new file mode 100644
index 0000000..9ef1a87
--- /dev/null
+++ b/prolog/problems/clp_fd/gcd_3/sl.py
@@ -0,0 +1,14 @@
+# coding=utf-8
+
+name = 'gcd/3'
+slug = 'Največji skupni delitelj'
+
+description = '''\
+<p><code>gcd(X, Y, GCD)</code>: <code>GCD</code> je največji skupni delitelj števil <code>X</code> in <code>Y</code>. Implementiraj ta predikat z uporabo omejitev.</p>
+<p>Namig: poskusi najprej napisati predikat, ki poišče <em>vse</em> skupne delitelje dveh števil.</p>
+<pre>
+ ?- gcd(36, 84, GCD).
+ GCD = 12.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/clp_fd/magic_1/common.py b/prolog/problems/clp_fd/magic_1/common.py
index 17a9199..3ffe72f 100644
--- a/prolog/problems/clp_fd/magic_1/common.py
+++ b/prolog/problems/clp_fd/magic_1/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 151
number = 60
visible = True
@@ -16,3 +20,37 @@ magic(L):-
A1+B1+C1 #= A3+B3+C3,
A1+B2+C3 #= A3+B2+C1,
labeling([], L).'''
+
+test_cases = [
+ ('magic(X)',
+ [{'X': '[2, 7, 6, 9, 5, 1, 4, 3, 8]'}]),
+ ('magic(X)',
+ [{'X': '[2, 9, 4, 7, 5, 3, 6, 1, 8]'}]),
+ ('setof(S, magic(S), X)',
+ [{'X': '[[2, 7, 6, 9, 5, 1, 4, 3, 8], [2, 9, 4, 7, 5, 3, 6, 1, 8], \
+ [4, 3, 8, 9, 5, 1, 2, 7, 6], [4, 9, 2, 3, 5, 7, 8, 1, 6], \
+ [6, 1, 8, 7, 5, 3, 2, 9, 4], [6, 7, 2, 1, 5, 9, 8, 3, 4], \
+ [8, 1, 6, 3, 5, 7, 4, 9, 2], [8, 3, 4, 1, 5, 9, 6, 7, 2]]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/clp_fd/magic_1/sl.py b/prolog/problems/clp_fd/magic_1/sl.py
new file mode 100644
index 0000000..8cf040e
--- /dev/null
+++ b/prolog/problems/clp_fd/magic_1/sl.py
@@ -0,0 +1,14 @@
+# coding=utf-8
+
+name = 'magic/1'
+slug = '3x3 magični kvadrat'
+
+description = '''\
+<p><code>magic(S)</code>: seznam <code>S</code> predstavlja 3×3 magični kvadrat (<code>S</code> je permutacija števil 1 do 9 -- tri števila tvorijo eno vrstico). Vsote števil v vsaki vrstici, stolpcu in glavni diagonali magičnega kvadrata so enake. Implementiraj ta predikat z uporabo omejitev. Predikat naj vrne vse rešitve, eno po eno.</p>
+<pre>
+ ?- magic(S).
+ S = [2, 7, 6, 9, 5, 1, 4, 3, 8] ;
+ …
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/clp_fd/puzzle_abc_3/common.py b/prolog/problems/clp_fd/puzzle_abc_3/common.py
index 1563e1f..ffce416 100644
--- a/prolog/problems/clp_fd/puzzle_abc_3/common.py
+++ b/prolog/problems/clp_fd/puzzle_abc_3/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 153
number = 57
visible = True
@@ -13,3 +17,32 @@ puzzle_abc(A, B, C) :-
[A,B,C] ins 0..inf,
labeling([], [A,B,C]).
'''
+
+test_cases = [
+ ('puzzle_abc(A, B, C)',
+ [{'A': '12', 'B': '10', 'C': '5'}]),
+ ('setof(A/B/C, puzzle_abc(A, B, C), X)',
+ [{'X': '[12/10/5]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/clp_fd/puzzle_abc_3/sl.py b/prolog/problems/clp_fd/puzzle_abc_3/sl.py
new file mode 100644
index 0000000..118481a
--- /dev/null
+++ b/prolog/problems/clp_fd/puzzle_abc_3/sl.py
@@ -0,0 +1,10 @@
+# coding=utf-8
+
+name = 'puzzle_abc/3'
+slug = 'Uganka z leti: ABC'
+
+description = '''\
+<p>Oseba <code>A</code> je dve leti starejša od osebe <code>B</code>, ki je dvakrat starejša od osebe <code>C</code>. Skupaj so osebe A, B in C stare 27 let.</p>
+<p>Napiši predikat <code>puzzle_abc(A, B, C)</code>, ki izračuna koliko so stare osebe A, B in C.</p>'''
+
+hint = {}
diff --git a/prolog/problems/clp_fd/puzzle_beth_1/common.py b/prolog/problems/clp_fd/puzzle_beth_1/common.py
index bf81396..fb00516 100644
--- a/prolog/problems/clp_fd/puzzle_beth_1/common.py
+++ b/prolog/problems/clp_fd/puzzle_beth_1/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 155
number = 56
visible = True
@@ -8,3 +12,32 @@ facts = None
solution = '''\
puzzle_beth(X) :-
X + 2 #= 2*(X-5).'''
+
+test_cases = [
+ ('puzzle_beth(X)',
+ [{'X': '12'}]),
+ ('setof(A, puzzle_beth(A), X)',
+ [{'X': '[12]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/clp_fd/puzzle_beth_1/sl.py b/prolog/problems/clp_fd/puzzle_beth_1/sl.py
new file mode 100644
index 0000000..261ec74
--- /dev/null
+++ b/prolog/problems/clp_fd/puzzle_beth_1/sl.py
@@ -0,0 +1,11 @@
+# coding=utf-8
+
+name = 'puzzle_beth/1'
+slug = 'Uganka z leti: Beti'
+
+description = '''\
+<p>Ko so Beti vprašali koliko je stara, je odgovorila takole "Čez dve leti bom dvakrat starejša kot sem bila pet let nazaj".</p>
+<p>Napiši predikat <code>puzzle_beth(X)</code>, ki izračuna njeno trenutno starost <code>X</code>.</p>
+'''
+
+hint = {}
diff --git a/prolog/problems/clp_fd/puzzle_momson_2/common.py b/prolog/problems/clp_fd/puzzle_momson_2/common.py
index 9cef246..906bd15 100644
--- a/prolog/problems/clp_fd/puzzle_momson_2/common.py
+++ b/prolog/problems/clp_fd/puzzle_momson_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 152
number = 58
visible = True
@@ -13,3 +17,34 @@ puzzle_momson(M, S) :-
M + S #= 66,
M #> S,
labeling([], [M, S]).'''
+
+test_cases = [
+ ('puzzle_momson(M, S)',
+ [{'M': '42', 'S': '24'}]),
+ ('puzzle_momson(M, S)',
+ [{'M': '51', 'S': '15'}]),
+ ('setof(M/S, puzzle_momson(M, S), X)',
+ [{'X': '[42/24, 51/15]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/clp_fd/puzzle_momson_2/sl.py b/prolog/problems/clp_fd/puzzle_momson_2/sl.py
new file mode 100644
index 0000000..593f153
--- /dev/null
+++ b/prolog/problems/clp_fd/puzzle_momson_2/sl.py
@@ -0,0 +1,10 @@
+# coding=utf-8
+
+name = 'puzzle_momson/2'
+slug = 'Uganka z leti: mama in sin'
+
+description = '''\
+<p>Mama in sin sta skupaj stara 66 let. Mamina leta so ravno sinova obrnjena leta (obrnjene so cifre). Koliko sta stara?</p>
+<p>Napiši predikat <code>puzzle_momson(M, S)</code>, ki izračuna starost mame <code>M</code> in sina <code>S</code>.</p>'''
+
+hint = {}
diff --git a/prolog/problems/clp_fd/puzzle_ratio_2/common.py b/prolog/problems/clp_fd/puzzle_ratio_2/common.py
index 73b9234..736cd2e 100644
--- a/prolog/problems/clp_fd/puzzle_ratio_2/common.py
+++ b/prolog/problems/clp_fd/puzzle_ratio_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 154
number = 59
visible = True
@@ -16,3 +20,32 @@ puzzle_ratio(A, B) :-
A #< 200,
B #< 200,
labeling([], [A, B]).'''
+
+test_cases = [
+ ('puzzle_ratio(A, B)',
+ [{'A': '30', 'B': '24'}]),
+ ('setof(A/B, puzzle_ratio(A, B), X)',
+ [{'X': '[30/24]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/clp_fd/puzzle_ratio_2/sl.py b/prolog/problems/clp_fd/puzzle_ratio_2/sl.py
new file mode 100644
index 0000000..826e66f
--- /dev/null
+++ b/prolog/problems/clp_fd/puzzle_ratio_2/sl.py
@@ -0,0 +1,10 @@
+# coding=utf-8
+
+name = 'puzzle_ratio/2'
+slug = 'Uganka z leti: razmerje'
+
+description = '''\
+<p>Trenutni starosti osebe <code>A</code> in osebe <code>B</code> sta v razmerju 5:4. Čez tri leta bo razmerje njunih let postalo 11:9.</p>
+<p>Napiši predikat <code>puzzle_ratio(A, B)</code>, ki izračuna starost osebe <code>A</code> in osebe <code>B</code>.</p>'''
+
+hint = {}
diff --git a/prolog/problems/clp_fd/tobase_3/common.py b/prolog/problems/clp_fd/tobase_3/common.py
index 5d160d7..3783396 100644
--- a/prolog/problems/clp_fd/tobase_3/common.py
+++ b/prolog/problems/clp_fd/tobase_3/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 150
number = 62
visible = True
@@ -14,3 +18,42 @@ tobase(N, B, Nb) :-
Rem #>= 0, Rem #< B,
Nb #= Nb1 * 10 + Rem,
tobase(N1, B, Nb1).'''
+
+test_cases = [
+ ('tobase(214, 2, X)',
+ [{'X': '11010110'}]),
+ ('tobase(321, 7, X)',
+ [{'X': '636'}]),
+ ('tobase(X, 8, 777)',
+ [{'X': '511'}]),
+ ('tobase(X, 8, 132)',
+ [{'X': '90'}]),
+ ('tobase(653, X, 10103)',
+ [{'X': '5'}]),
+ ('tobase(123, X, 146)',
+ [{'X': '9'}]),
+ ('setof(B/N, tobase(123, B, N), X)',
+ [{'X': '[2/1111011, 3/11120, 4/1323, 5/443, 6/323, 7/234, 8/173, 9/146, 10/123]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/clp_fd/tobase_3/sl.py b/prolog/problems/clp_fd/tobase_3/sl.py
new file mode 100644
index 0000000..a775808
--- /dev/null
+++ b/prolog/problems/clp_fd/tobase_3/sl.py
@@ -0,0 +1,17 @@
+# coding=utf-8
+
+name = 'tobase/3'
+slug = 'Pretvori števila v/iz desetiškega sistema'
+
+description = '''\
+<p><code>tobase(Number, B, X)</code>: število <code>Number</code> je v desetiškem sistemu. <code>X</code> predstavlja to število v sistemu z bazo <code>B</code>. Implementiraj predikat z uporabo omejitev. Omeji vrednost <code>B</code> na interval [2..10].</p>
+<pre>
+ ?- tobase(42, 2, X).
+ X = 101010.
+ ?- tobase(N, 2, 101010).
+ N = 42.
+ ?- tobase(42, B, 101010).
+ B = 2.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/clp_r/common.py b/prolog/problems/clp_r/common.py
index 2238250..4136a33 100644
--- a/prolog/problems/clp_r/common.py
+++ b/prolog/problems/clp_r/common.py
@@ -1,2 +1,4 @@
id = 9
number = 8
+
+allowed_groups = ['lists']
diff --git a/prolog/problems/dcg/ab_2/sl.py b/prolog/problems/dcg/ab_2/sl.py
new file mode 100644
index 0000000..d2d8924
--- /dev/null
+++ b/prolog/problems/dcg/ab_2/sl.py
@@ -0,0 +1,11 @@
+# coding=utf-8
+
+name = 'ab/2'
+slug = 'a*b*'
+
+description = '''\
+<p>Napiši DCG gramatiko z začetnim simbolom <code>ab</code> za jezik <code>a<sup>m</sup>b<sup>n</sup></code>, kjer sta m, n ≥ 0.</p>
+<p>Primeri veljavnih besed: <code>[]</code>, <code>a</code>, <code>aab</code>, <code>abbb</code>, <code>bbb</code>.</p>
+<p>Namig: za generiranje vedno daljših besed uporabi poizvedbo <code>conc(Word,_,_), ab(Word,[])</code>.</p>'''
+
+hint = {}
diff --git a/prolog/problems/dcg/common.py b/prolog/problems/dcg/common.py
index 4992f2d..19fc104 100644
--- a/prolog/problems/dcg/common.py
+++ b/prolog/problems/dcg/common.py
@@ -1,2 +1,4 @@
id = 10
number = 9
+
+allowed_groups = ['dcg', 'lists']
diff --git a/prolog/problems/dcg/digit_2/sl.py b/prolog/problems/dcg/digit_2/sl.py
new file mode 100644
index 0000000..393e0e1
--- /dev/null
+++ b/prolog/problems/dcg/digit_2/sl.py
@@ -0,0 +1,9 @@
+# coding=utf-8
+
+name = 'digit/2'
+slug = 'Cifra'
+
+description = '''\
+<p>Napiši gramatiko z začetnim simbolom <code>digit</code> za jezik definiran z naslednjo množico: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.</p>'''
+
+hint = {}
diff --git a/prolog/problems/dcg/expr_2/sl.py b/prolog/problems/dcg/expr_2/sl.py
new file mode 100644
index 0000000..6401deb
--- /dev/null
+++ b/prolog/problems/dcg/expr_2/sl.py
@@ -0,0 +1,11 @@
+# coding=utf-8
+
+name = 'expr/2'
+slug = 'Aritmetični izrazi'
+
+description = '''\
+<p>Napiši gramatiko z začetnim simbolom <code>expr</code> za jezik aritmetičnih izrazov, ki vsebujejo števila (brez vodilnih ničel), vsoto in množenje. Podizrazi se lahko združujejo z oklepaji.</p>
+<p>Primeri veljavnih besed: <code>(1+2)*3</code>, <code>42*8*3</code>, <code>(2+1)*(3+4)</code>.</p>
+'''
+
+hint = {}
diff --git a/prolog/problems/dcg/expr_3/sl.py b/prolog/problems/dcg/expr_3/sl.py
new file mode 100644
index 0000000..734a6ea
--- /dev/null
+++ b/prolog/problems/dcg/expr_3/sl.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+
+name = 'expr/3'
+slug = 'Aritmetični izrazi s pomenom'
+
+description = '''\
+<p>Napiši gramatiko z začetnim simbolom <code>expr</code> za jezik aritmetičnih izrazov, ki vsebujejo števila (brez vodilnih ničel), vsoto in množenje. Podizrazi se lahko združujejo z oklepaji. Pomen besede v tem jeziku je numerična vrednost predstavljenega izraza.</p>
+<p>Primeri veljavnih besed: <code>(1+2)*3</code>, <code>42*8*3</code>, <code>(2+1)*(3+4)</code>.</p>
+<pre>
+ ?- expr(N, ['(',2,'+',1,')','*','(',3,'+',4,')'], []). % (2+1)*(3+4) = 21
+ N = 21.
+</pre>
+'''
+
+hint = {}
diff --git a/prolog/problems/dcg/flower_2/sl.py b/prolog/problems/dcg/flower_2/sl.py
new file mode 100644
index 0000000..30e4118
--- /dev/null
+++ b/prolog/problems/dcg/flower_2/sl.py
@@ -0,0 +1,11 @@
+# coding=utf-8
+
+name = 'flower/2'
+slug = 'Besede v obliki "rožice", npr. +++--+++'
+
+description = '''\
+<p>Napiši gramatiko z začetnim simbolom <code>flower</code> za jezik <code>+<sup>n</sup>-<sup>m</sup>+<sup>n</sup></code>, kjer je m > 0 in n ≥ 0.</p>
+<p>Primeri veljavnih besed: <code>-</code>, <code>++-++</code>, <code>+---+</code>.</p>
+'''
+
+hint = {}
diff --git a/prolog/problems/dcg/number_2/sl.py b/prolog/problems/dcg/number_2/sl.py
new file mode 100644
index 0000000..cdcbcee
--- /dev/null
+++ b/prolog/problems/dcg/number_2/sl.py
@@ -0,0 +1,10 @@
+# coding=utf-8
+
+name = 'number/2'
+slug = 'Števila z dovoljenimi vodilnimi ničlami'
+
+description = '''\
+<p>Napiši gramatiko z začetnim simbolom <code>number</code> za jezik nenegativnih celih števil. Števila lahko vsebujejo vodilne ničle.</p>
+<p>Primeri veljavnih besed: <code>123</code>, <code>54</code>, <code>0122</code>, <code>0001221</code>, <code>0</code>.</p>'''
+
+hint = {}
diff --git a/prolog/problems/dcg/number_3/sl.py b/prolog/problems/dcg/number_3/sl.py
new file mode 100644
index 0000000..eeb4db2
--- /dev/null
+++ b/prolog/problems/dcg/number_3/sl.py
@@ -0,0 +1,14 @@
+# coding=utf-8
+
+name = 'number/3'
+slug = 'Števila s pomenom'
+
+description = '''\
+<p>Napiši gramatiko z začetnim simbolom <code>number</code> za jezik nenegativnih celih števil. Števila lahko vsebujejo vodilne ničle. Pomen besede v tem jeziku je kar numerična vrednost predstavljenega števila.</p>
+<pre>
+ ?- number(N, [1,2,3,4], []).
+ N = 1234.
+</pre>
+'''
+
+hint = {}
diff --git a/prolog/problems/dcg/number_proper_2/sl.py b/prolog/problems/dcg/number_proper_2/sl.py
new file mode 100644
index 0000000..1b39977
--- /dev/null
+++ b/prolog/problems/dcg/number_proper_2/sl.py
@@ -0,0 +1,10 @@
+# coding=utf-8
+
+name = 'number_proper/2'
+slug = 'Števila brez vodilnih ničel'
+
+description = '''\
+<p>Napiši gramatiko z začetnim simbolom <code>number</code> za jezik nenegativnih celih števil. Števila <em>ne smejo</em> vsebovati vodilnih ničel.</p>
+<p>Primeri veljavnih besed: <code>123</code>, <code>54</code>, <code>122</code>, <code>1221</code>, <code>0</code>.</p>'''
+
+hint = {}
diff --git a/prolog/problems/dcg/paren_2/sl.py b/prolog/problems/dcg/paren_2/sl.py
new file mode 100644
index 0000000..0ec52cc
--- /dev/null
+++ b/prolog/problems/dcg/paren_2/sl.py
@@ -0,0 +1,11 @@
+# coding=utf-8
+
+name = 'paren/2'
+slug = 'Pravilno gnezdeni oklepaji'
+
+description = '''\
+<p>Napiši gramatiko z začetnim simbolom <code>paren</code> za jezik pravilno gnezdenih zaporedij oklepajev. Terminale v tej gramatiki piši takole: <code>['(']</code> in <code>[')']</code>.</p>
+<p>Primeri veljavnih besed: <code>()</code>, <code>(())</code>, <code>()(())</code>, <code>(()())()</code>.</p>
+<p>Primeri neveljavnih besed: <code>)(</code>, <code>((()</code>, <code>))</code>.</p>'''
+
+hint = {}
diff --git a/prolog/problems/dcg/paren_3/sl.py b/prolog/problems/dcg/paren_3/sl.py
new file mode 100644
index 0000000..a98eb8b
--- /dev/null
+++ b/prolog/problems/dcg/paren_3/sl.py
@@ -0,0 +1,14 @@
+# coding=utf-8
+
+name = 'paren/3'
+slug = 'Pravilno gnezdeni oklepaji s pomenom'
+
+description = '''\
+<p>Napiši gramatiko z začetnim simbolom <code>paren</code> za jezik pravilno gnezdenih zaporedij oklepajev. Pomen besede v tem jeziku je največja globina gnezdenja oklepajev.</p>
+<pre>
+ ?- paren(D, ['(','(',')',')','(',')'], []). % (())()
+ D = 2.
+</pre>
+'''
+
+hint = {}
diff --git a/prolog/problems/denotational_semantics/algol_3/common.py b/prolog/problems/denotational_semantics/algol_3/common.py
index cce9b69..d7607c4 100644
--- a/prolog/problems/denotational_semantics/algol_3/common.py
+++ b/prolog/problems/denotational_semantics/algol_3/common.py
@@ -2,7 +2,7 @@
id = 176
number = 83
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/problems/denotational_semantics/algol_for_3/common.py b/prolog/problems/denotational_semantics/algol_for_3/common.py
index 4cf9373..3261c99 100644
--- a/prolog/problems/denotational_semantics/algol_for_3/common.py
+++ b/prolog/problems/denotational_semantics/algol_for_3/common.py
@@ -2,7 +2,7 @@
id = 178
number = 85
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/problems/denotational_semantics/algol_if_3/common.py b/prolog/problems/denotational_semantics/algol_if_3/common.py
index 0c52886..faf0e4c 100644
--- a/prolog/problems/denotational_semantics/algol_if_3/common.py
+++ b/prolog/problems/denotational_semantics/algol_if_3/common.py
@@ -2,7 +2,7 @@
id = 177
number = 84
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/problems/denotational_semantics/common.py b/prolog/problems/denotational_semantics/common.py
index e2c420e..57be52d 100644
--- a/prolog/problems/denotational_semantics/common.py
+++ b/prolog/problems/denotational_semantics/common.py
@@ -1,2 +1,4 @@
id = 11
number = 10
+
+allowed_groups = ['lists']
diff --git a/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py b/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py
index d994039..c6d4db0 100644
--- a/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py
+++ b/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py
@@ -2,7 +2,7 @@
id = 172
number = 81
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py b/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
index 15dce6b..494f628 100644
--- a/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
+++ b/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
@@ -2,7 +2,7 @@
id = 173
number = 82
-visible = True
+visible = False
facts = 'denotational_semantics_aux__predicates'
solution = '''\
diff --git a/prolog/problems/denotational_semantics/prog_listswap_2/common.py b/prolog/problems/denotational_semantics/prog_listswap_2/common.py
index 1f8b655..020b31c 100644
--- a/prolog/problems/denotational_semantics/prog_listswap_2/common.py
+++ b/prolog/problems/denotational_semantics/prog_listswap_2/common.py
@@ -2,7 +2,7 @@
id = 175
number = 79
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/problems/denotational_semantics/prog_listswap_3/common.py b/prolog/problems/denotational_semantics/prog_listswap_3/common.py
index a40be29..6f96f85 100644
--- a/prolog/problems/denotational_semantics/prog_listswap_3/common.py
+++ b/prolog/problems/denotational_semantics/prog_listswap_3/common.py
@@ -2,7 +2,7 @@
id = 174
number = 80
-visible = True
+visible = False
facts = 'denotational_semantics_aux__predicates'
solution = '''\
diff --git a/prolog/problems/family_relations/ancestor_2/common.py b/prolog/problems/family_relations/ancestor_2/common.py
index 68cbc6d..48ea512 100644
--- a/prolog/problems/family_relations/ancestor_2/common.py
+++ b/prolog/problems/family_relations/ancestor_2/common.py
@@ -40,15 +40,11 @@ test_cases = [
[{'X': 'vanessa'}, {'X': 'patrick'}, {'X': 'tina'}, {'X': 'thomas'}, {'X': 'william'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
-
+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/family_relations/aunt_2/common.py b/prolog/problems/family_relations/aunt_2/common.py
index b0a18bf..507460f 100644
--- a/prolog/problems/family_relations/aunt_2/common.py
+++ b/prolog/problems/family_relations/aunt_2/common.py
@@ -44,15 +44,11 @@ test_cases = [
[{'X': 'vanessa'}, {'X': 'patricia'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
-
+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/family_relations/brother_2/common.py b/prolog/problems/family_relations/brother_2/common.py
index 4d01c0b..556d0e9 100644
--- a/prolog/problems/family_relations/brother_2/common.py
+++ b/prolog/problems/family_relations/brother_2/common.py
@@ -38,15 +38,11 @@ test_cases = [
[{'X': 'jeffrey'}, {'X': 'william'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
-
+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/family_relations/common.py b/prolog/problems/family_relations/common.py
index 5aff819..f292faa 100644
--- a/prolog/problems/family_relations/common.py
+++ b/prolog/problems/family_relations/common.py
@@ -1,2 +1,4 @@
id = 1
number = 1
+
+allowed_groups = ['family_relations']
diff --git a/prolog/problems/family_relations/connected_3/common.py b/prolog/problems/family_relations/connected_3/common.py
index 2555fe9..31d0d12 100644
--- a/prolog/problems/family_relations/connected_3/common.py
+++ b/prolog/problems/family_relations/connected_3/common.py
@@ -6,7 +6,7 @@ import server.problems
id = 102
number = 9
-visible = True
+visible = False
facts = 'family_relations'
solution = '''\
@@ -29,15 +29,11 @@ test_cases = [
# [{'X': 'vanessa'}, {'X': 'patricia'}, {'X': 'susan'}, {'X': 'john'}, {'X': 'michael'}, {'X': 'michelle'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
-
+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/family_relations/cousin_2/common.py b/prolog/problems/family_relations/cousin_2/common.py
index 382c7a0..0f7a37d 100644
--- a/prolog/problems/family_relations/cousin_2/common.py
+++ b/prolog/problems/family_relations/cousin_2/common.py
@@ -51,15 +51,11 @@ test_cases = [
[{'X': 'andrew'}, {'X': 'melanie'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
-
+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/family_relations/descendant_2/common.py b/prolog/problems/family_relations/descendant_2/common.py
index e979b0f..f419b1d 100644
--- a/prolog/problems/family_relations/descendant_2/common.py
+++ b/prolog/problems/family_relations/descendant_2/common.py
@@ -40,15 +40,11 @@ test_cases = [
[{'X': 'vanessa'}, {'X': 'patricia'}, {'X': 'susan'}, {'X': 'john'}, {'X': 'michael'}, {'X': 'michelle'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
-
+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/family_relations/father_2/common.py b/prolog/problems/family_relations/father_2/common.py
index 45b9255..f5888de 100644
--- a/prolog/problems/family_relations/father_2/common.py
+++ b/prolog/problems/family_relations/father_2/common.py
@@ -41,15 +41,11 @@ test_cases = [
[{'X': 'aleksandr'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
-
+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/family_relations/grandparent_2/common.py b/prolog/problems/family_relations/grandparent_2/common.py
index 0c902da..663c9e4 100644
--- a/prolog/problems/family_relations/grandparent_2/common.py
+++ b/prolog/problems/family_relations/grandparent_2/common.py
@@ -42,15 +42,11 @@ test_cases = [
[{'X': 'vanessa'}, {'X': 'patricia'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
-
+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/family_relations/mother_2/common.py b/prolog/problems/family_relations/mother_2/common.py
index 535e7ed..0a4c7bf 100644
--- a/prolog/problems/family_relations/mother_2/common.py
+++ b/prolog/problems/family_relations/mother_2/common.py
@@ -42,15 +42,11 @@ test_cases = [
[{'X': 'steve'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
-
+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/family_relations/sister_2/common.py b/prolog/problems/family_relations/sister_2/common.py
index 1eb4a6a..90039e3 100644
--- a/prolog/problems/family_relations/sister_2/common.py
+++ b/prolog/problems/family_relations/sister_2/common.py
@@ -39,15 +39,11 @@ test_cases = [
[{'X': 'melanie'}]),
]
-def test(program, solved_problems):
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
-
+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/license_plates/checklicenseplate_3/common.py b/prolog/problems/license_plates/checklicenseplate_3/common.py
index c37e210..6741e69 100644
--- a/prolog/problems/license_plates/checklicenseplate_3/common.py
+++ b/prolog/problems/license_plates/checklicenseplate_3/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 148
number = 55
visible = True
@@ -51,3 +55,40 @@ checkLicensePlate(LP, E1, E2) :-
genexp148(MN2, E2),
E1 =:= E2.
'''
+
+test_cases = [
+ ('''checkLicensePlate([l, j, l, 3, '-', 2, 4, 2], E1, E2)''',
+ [{'E1': '-3', 'E2': '(-2-4)/2'}, {'E1': '3', 'E2': '(2+4)/2'},
+ {'E1': '-3*2', 'E2': '-4-2'}, {'E1': '3*2', 'E2': '4+2'},
+ {'E1': '-3*2+4', 'E2': '-2'}, {'E1': '3*2-4', 'E2': '2'}]),
+ ('''checkLicensePlate([k, r, a, 3, '-', 2, 1, 7], E1, E2)''',
+ [{'E1': '-3', 'E2': '-21/7'}, {'E1': '3', 'E2': '21/7'},
+ {'E1': '-3*2', 'E2': '1-7'}, {'E1': '3*2', 'E2': '-1+7'},
+ {'E1': '3*2+1', 'E2': '7'}, {'E1': '-3*2-1', 'E2': '-7'}]),
+ ('''checkLicensePlate([g, o, c, 8, '-', 2, 1, 3], E1, E2)''',
+ [{'E1': '-8', 'E2': '-2*(1+3)'}, {'E1': '8', 'E2': '2*(1+3)'},
+ {'E1': '-8/2+1', 'E2': '-3'}, {'E1': '8/2-1', 'E2': '3'},
+ {'E1': '-8/2', 'E2': '-1-3'}, {'E1': '8/2', 'E2': '1+3'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/license_plates/checklicenseplate_3/sl.py b/prolog/problems/license_plates/checklicenseplate_3/sl.py
new file mode 100644
index 0000000..2e3ec65
--- /dev/null
+++ b/prolog/problems/license_plates/checklicenseplate_3/sl.py
@@ -0,0 +1,18 @@
+# coding=utf-8
+
+name = 'checkLicensePlate/3'
+slug = 'Preveri, če lahko iz številk v registrski tablici sestaviš veljavno enačbo'
+
+description = '''\
+<p><code>checkLicensePlate(LP, E1, E2)</code>: iz cifer v seznamu <code>LP</code> se da sestaviti veljavno enačbo <code>E1</code> = <code>E2</code>. <code>E1</code> in <code>E2</code> sta aritmetična izraza, sestavljena iz podseznamov <code>Plate</code> z uporabo aritmetičnih operatorjev (<code>+</code>, <code>-</code>, <code>*</code> and <code>/</code>). Dodaten unarni minus se lahko vstavi na začetek izrazov <code>E1</code> in <code>E2</code>.</p>
+<pre>
+ ?- checkLicensePlate([l,j,l,3,-,2,1,7], E1, E2).
+ E1 = 3, E2 = 21/7 ;
+ E1 = -3, E2 = -21/7 ;
+ E1 = 3*2, E2 = -1+7 ;
+ E1 = -3*2, E2 = 1-7 ;
+ E1 = 3*2+1, E2 = 7 ;
+ E1 = -3*2-1, E2 = -7.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/license_plates/common.py b/prolog/problems/license_plates/common.py
index 3d15487..eab76a6 100644
--- a/prolog/problems/license_plates/common.py
+++ b/prolog/problems/license_plates/common.py
@@ -1,2 +1,4 @@
id = 7
number = 6
+
+allowed_groups = ['license_plates', 'lists']
diff --git a/prolog/problems/license_plates/firstminus_2/common.py b/prolog/problems/license_plates/firstminus_2/common.py
index 20376d2..8831fe2 100644
--- a/prolog/problems/license_plates/firstminus_2/common.py
+++ b/prolog/problems/license_plates/firstminus_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 147
number = 54
visible = True
@@ -10,3 +14,32 @@ firstMinus(L, L).
firstMinus([X|T], [Y|T]) :-
Y is -X.
'''
+
+test_cases = [
+ ('firstMinus([2, 3, 4], X)',
+ [{'X': '[2, 3, 4]'}, {'X': '[-2, 3, 4]'}]),
+ ('firstMinus([5, 2, 3, 4], X)',
+ [{'X': '[5, 2, 3, 4]'}, {'X': '[-5, 2, 3, 4]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/license_plates/firstminus_2/sl.py b/prolog/problems/license_plates/firstminus_2/sl.py
new file mode 100644
index 0000000..d480994
--- /dev/null
+++ b/prolog/problems/license_plates/firstminus_2/sl.py
@@ -0,0 +1,14 @@
+# coding=utf-8
+
+name = 'firstMinus/2'
+slug = 'Negiraj prvi element v danem seznamu števil'
+
+description = '''\
+<p><code>firstMinus(L1, L2)</code>: seznam <code>L2</code> je enak kot <code>L1</code>, razen prvega elementa, ki je lahko negiran ali pa ne. Predikat naj vrne obe rešitvi, eno za drugo.</p>
+<pre>
+ ?- firstMinus([1,2,3], L).
+ L = [1,2,3] ;
+ L = [-1,2,3].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/license_plates/genexp_2/common.py b/prolog/problems/license_plates/genexp_2/common.py
index ecdc772..6c3dd17 100644
--- a/prolog/problems/license_plates/genexp_2/common.py
+++ b/prolog/problems/license_plates/genexp_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 146
number = 53
visible = True
@@ -22,3 +26,41 @@ genexp(L, Exp) :-
conc146(Before, [NExp|After], L1),
genexp(L1, Exp).
'''
+
+test_cases = [
+ ('genexp([1], X)',
+ [{'X': '1'}]),
+ ('genexp([1, 2], X)',
+ [{'X': '1*2'}, {'X': '1+2'}, {'X': '1-2'}, {'X': '1/2'}]),
+ ('genexp([1, 2, 3], X)',
+ [{'X': '1+2+3'}, {'X': '1+2-3'}, {'X': '(1+2)*3'}, {'X': '(1+2)/3'},
+ {'X': '1-2+3'}, {'X': '1-2-3'}, {'X': '(1-2)*3'}, {'X': '(1-2)/3'},
+ {'X': '1*2+3'}, {'X': '1*2-3'}, {'X': '1*2*3'}, {'X': '1*2/3'},
+ {'X': '1/2+3'}, {'X': '1/2-3'}, {'X': '1/2*3'}, {'X': '1/2/3'},
+ {'X': '1+(2+3)'}, {'X': '1-(2+3)'}, {'X': '1*(2+3)'}, {'X': '1/(2+3)'},
+ {'X': '1+(2-3)'}, {'X': '1-(2-3)'}, {'X': '1*(2-3)'}, {'X': '1/(2-3)'},
+ {'X': '1+2*3'}, {'X': '1-2*3'}, {'X': '1*(2*3)'}, {'X': '1/(2*3)'},
+ {'X': '1+2/3'}, {'X': '1-2/3'}, {'X': '1*(2/3)'}, {'X': '1/(2/3)'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/license_plates/genexp_2/sl.py b/prolog/problems/license_plates/genexp_2/sl.py
new file mode 100644
index 0000000..9160f27
--- /dev/null
+++ b/prolog/problems/license_plates/genexp_2/sl.py
@@ -0,0 +1,19 @@
+# coding=utf-8
+
+name = 'genexp/2'
+slug = 'Sestavi aritmetični izraz iz številk v podanem seznamu'
+
+description = '''\
+<p><code>genexp(L, E)</code>: Izraz <code>E</code> je zgrajen iz številk v seznamu <code>L</code> z dodajanjem aritmetičnih operatorjev. Predikat naj vrača vse možne izraze, enega po enega.</p>
+<pre>
+ ?- genexp([1,2,3], L).
+ L = 1+2+3 ;
+ L = 1+2-3 ;
+ L = (1+2)*3 ;
+ L = (1+2)/3 ;
+ L = 1-2+3 ;
+ L = 1-2-3 ;
+ ...
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/license_plates/getdigits_2/common.py b/prolog/problems/license_plates/getdigits_2/common.py
index 82fe033..6650b5a 100644
--- a/prolog/problems/license_plates/getdigits_2/common.py
+++ b/prolog/problems/license_plates/getdigits_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 144
number = 51
visible = True
@@ -13,3 +17,34 @@ getdigits([X|T], [X|NT]) :-
getdigits([_|T], NT) :-
getdigits(T, NT).
'''
+
+test_cases = [
+ ('getdigits([], X)',
+ [{'X': '[]'}]),
+ ('''getdigits([1, [], 2, a, b, -3, '+', 4], X)''',
+ [{'X': '[1, 2, -3, 4]'}]),
+ ('''getdigits([l, j, k, 3, '-', 2, 4, 2], X)''',
+ [{'X': '[3, 2, 4, 2]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/license_plates/getdigits_2/sl.py b/prolog/problems/license_plates/getdigits_2/sl.py
new file mode 100644
index 0000000..3f59e90
--- /dev/null
+++ b/prolog/problems/license_plates/getdigits_2/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'getdigits/2'
+slug = 'Vrni vse številke iz podanega seznama'
+
+description = '''\
+<p><code>getdigits(L, DL)</code>: seznam <code>DL</code> vsebuje vse številke iz seznama <code>L</code>, vrstni red elementov se ohrani.</p>
+<pre>
+ ?- getdigits([2,3,e,-,4,b], DL).
+ DL = [2,3,4].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/license_plates/joindigits_2/common.py b/prolog/problems/license_plates/joindigits_2/common.py
index 9ebc037..1c5dba8 100644
--- a/prolog/problems/license_plates/joindigits_2/common.py
+++ b/prolog/problems/license_plates/joindigits_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 145
number = 52
visible = True
@@ -13,3 +17,33 @@ joindigits([X,Y|T], NT) :-
joindigits([X,Y|T], [X|NT]) :-
joindigits([Y|T], NT).
'''
+
+test_cases = [
+ ('joindigits([2, 3, 1, 4], X)',
+ [{'X': '[2, 3, 1, 4]'}, {'X': '[2, 3, 14]'}, {'X': '[2, 31, 4]'}, {'X': '[2, 314]'},
+ {'X': '[23, 1, 4]'}, {'X': '[23, 14]'}, {'X': '[231, 4]'}, {'X': '[2314]'}]),
+ ('joindigits([2, 3, 1], X)',
+ [{'X': '[2, 3, 1]'}, {'X': '[2, 31]'}, {'X': '[23, 1]'}, {'X': '[231]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/license_plates/joindigits_2/sl.py b/prolog/problems/license_plates/joindigits_2/sl.py
new file mode 100644
index 0000000..344d849
--- /dev/null
+++ b/prolog/problems/license_plates/joindigits_2/sl.py
@@ -0,0 +1,16 @@
+# coding=utf-8
+
+name = 'joindigits/2'
+slug = 'Združi sosednja števila v seznamu na vse možne načine'
+
+description = '''\
+<p><code>joindigits(L, NL)</code>: seznam <code>NL</code> dobimo iz seznama <code>L</code> tako, da poljubno združujemo sosednja števila. Predikat naj vrača vse možnosti, eno po eno.</p>
+<pre>
+ ?- joindigits([3,2,4], NL).
+ NL = [324] ;
+ NL = [32,4] ;
+ NL = [3,24] ;
+ NL = [3,2,4].
+</pre>'''
+
+hint = {}
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 = {}
diff --git a/prolog/problems/old_exams/common.py b/prolog/problems/old_exams/common.py
index 56857ba..949859b 100644
--- a/prolog/problems/old_exams/common.py
+++ b/prolog/problems/old_exams/common.py
@@ -1 +1,3 @@
id = 12
+
+allowed_groups = ['lists']
diff --git a/prolog/problems/other/common.py b/prolog/problems/other/common.py
index 50384ad..25978e7 100644
--- a/prolog/problems/other/common.py
+++ b/prolog/problems/other/common.py
@@ -1 +1,3 @@
id = 4
+
+allowed_groups = ['lists']
diff --git a/prolog/problems/sets/common.py b/prolog/problems/sets/common.py
index 104aa9d..9318010 100644
--- a/prolog/problems/sets/common.py
+++ b/prolog/problems/sets/common.py
@@ -1,2 +1,4 @@
id = 5
number = 4
+
+allowed_groups = ['sets', 'lists']
diff --git a/prolog/problems/sets/diff_3/common.py b/prolog/problems/sets/diff_3/common.py
index fee93b2..bfa3ce6 100644
--- a/prolog/problems/sets/diff_3/common.py
+++ b/prolog/problems/sets/diff_3/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 130
number = 37
visible = True
@@ -18,3 +22,40 @@ diff([H|T], S2, D) :-
memb130(H, S2),
diff(T, S2, D).
'''
+
+test_cases = [
+ ('diff([], [t, e, q], X)',
+ [{'X': '[]'}]),
+ ('diff([q, r, t], [], A), msort(A, X)',
+ [{'X': '[q, r, t]'}]),
+ ('diff([1, 2, 3, 8, 4, 6], [6, 0, 3, 4], A), msort(A, X)',
+ [{'X': '[1, 2, 8]'}]),
+ ('diff([1, 2, 3, 8, 7, 4, 6], [7, 8, 6], A), msort(A, X)',
+ [{'X': '[1, 2, 3, 4]'}]),
+ ('diff([1, 8, 2, 3, 7, 5], [7], A), msort(A, X)',
+ [{'X': '[1, 2, 3, 5, 8]'}]),
+ ('diff([t, w, q], [t, e, q, w, b], X)',
+ [{'X': '[]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/sets/diff_3/sl.py b/prolog/problems/sets/diff_3/sl.py
new file mode 100644
index 0000000..d9b89e7
--- /dev/null
+++ b/prolog/problems/sets/diff_3/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'diff/3'
+slug = 'Poišči razliko dveh množic'
+
+description = '''\
+<p><code>diff(S1, S2, D)</code>: seznam <code>D</code> vsebuje elemente iz <code>S1</code>, ki niso v <code>S2</code>.</p>
+<pre>
+ ?- diff([2,3,5,1,7,9], [3,7,4,5,6], D).
+ D = [2,1,9].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/sets/intersect_3/common.py b/prolog/problems/sets/intersect_3/common.py
index 501cdf3..55d2df5 100644
--- a/prolog/problems/sets/intersect_3/common.py
+++ b/prolog/problems/sets/intersect_3/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 129
number = 36
visible = True
@@ -17,3 +21,40 @@ intersect([H|T], S2, [H|I]) :-
intersect([_|T], S2, I):-
intersect(T, S2, I).
'''
+
+test_cases = [
+ ('intersect([], [a, b, d], X)',
+ [{'X': '[]'}]),
+ ('intersect([g, h, r], [], X)',
+ [{'X': '[]'}]),
+ ('intersect([2, 5, 4, 7, 1, 9, 8], [0, 2, 5, 6, 7, 9, 1], A), msort(A, X)',
+ [{'X': '[1, 2, 5, 7, 9]'}]),
+ ('intersect([4, 7, 1, 9, 8], [4, 2, 5, 6, 7, 9, 1], A), msort(A, X)',
+ [{'X': '[1, 4, 7, 9]'}]),
+ ('intersect([9, 3, 4, 2, 1, 7], [a, b, d], X)',
+ [{'X': '[]'}]),
+ ('intersect([9, 3, 4, 2, 1, 7], [4, 2, 5, 6, 7, 9, 1], A), msort(A, X)',
+ [{'X': '[1, 2, 4, 7, 9]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/sets/intersect_3/sl.py b/prolog/problems/sets/intersect_3/sl.py
new file mode 100644
index 0000000..a6af2d5
--- /dev/null
+++ b/prolog/problems/sets/intersect_3/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'intersect/3'
+slug = 'Poišči presek dveh množic'
+
+description = '''\
+<p><code>intersect(S1, S2, I)</code>: seznam <code>I</code> vsebuje presek elementov v <code>S1</code> in <code>S2</code>.</p>
+<pre>
+ ?- intersect([1,5,6,3,4,2], [8,1,5,9,4,3], I).
+ I = [1,5,3,4].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/sets/is_subset_2/common.py b/prolog/problems/sets/is_subset_2/common.py
index 4047146..0d78cd6 100644
--- a/prolog/problems/sets/is_subset_2/common.py
+++ b/prolog/problems/sets/is_subset_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 132
number = 39
visible = True
@@ -15,3 +19,36 @@ is_subset([H|T], S2) :-
memb132(H, S2),
is_subset(T, S2).
'''
+
+test_cases = [
+ ('is_subset(X, [])',
+ [{'X': '[]'}]),
+ ('is_subset([2, 1, 3], [3, 2, 1, 4, 6, 7])',
+ [{}]),
+ ('\+ is_subset([2, 1, 0, 3], [3, 2, 1, 4, 6, 7])',
+ [{}]),
+ ('is_subset([3, 2, 1, 4, 6, 7], [3, 2, 1, 4, 6, 7])',
+ [{}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/sets/is_subset_2/sl.py b/prolog/problems/sets/is_subset_2/sl.py
new file mode 100644
index 0000000..ccec5b0
--- /dev/null
+++ b/prolog/problems/sets/is_subset_2/sl.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+
+name = 'is_subset/2'
+slug = 'Preveri, če je prva množica podmnožica od druge'
+
+description = '''\
+<p><code>is_subset(S1, S2)</code>: množica <code>S1</code> je podmnožica od <code>S2</code>.</p>
+<pre>
+ ?- is_subset([2,1,3,5,0], [3,2,1,4,5,9]).
+ false.
+ ?- is_subset([2,1,3,5], [3,2,1,4,5,9]).
+ true.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/sets/is_superset_2/common.py b/prolog/problems/sets/is_superset_2/common.py
index 86e5dc7..59f2fda 100644
--- a/prolog/problems/sets/is_superset_2/common.py
+++ b/prolog/problems/sets/is_superset_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 131
number = 38
visible = True
@@ -15,3 +19,36 @@ is_superset(S1, [H|T]) :-
memb131(H, S1),
is_superset(S1, T).
'''
+
+test_cases = [
+ ('is_superset([], X)',
+ [{'X': '[]'}]),
+ ('is_superset([3, 2, 1, 4, 6, 7], [2, 1, 3])',
+ [{}]),
+ ('\+ is_superset([3, 2, 1, 4, 6, 7], [2, 1, 0, 3])',
+ [{}]),
+ ('is_superset([3, 2, 1, 4, 6, 7], [3, 2, 1, 4, 6, 7])',
+ [{}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/sets/is_superset_2/sl.py b/prolog/problems/sets/is_superset_2/sl.py
new file mode 100644
index 0000000..77d0d9d
--- /dev/null
+++ b/prolog/problems/sets/is_superset_2/sl.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+
+name = 'is_superset/2'
+slug = 'Preveri, če je prva množica nadmnožica od druge'
+
+description = '''\
+<p><code>is_superset(S1, S2)</code>: množica <code>S1</code> je nadmnožica (vsebuje vse elemente) od <code>S2</code>.</p>
+<pre>
+ ?- is_superset([3,2,1,4,5,9], [2,1,3,5]).
+ true.
+ ?- is_superset([3,2,1,4,5,9], [2,1,3,5,0]).
+ false.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/sets/powerset_2/common.py b/prolog/problems/sets/powerset_2/common.py
index c825430..e97603c 100644
--- a/prolog/problems/sets/powerset_2/common.py
+++ b/prolog/problems/sets/powerset_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 134
number = 41
visible = True
@@ -15,3 +19,34 @@ subset134([_|T], T1) :-
powerset(Set, PowerSet) :-
findall(S, subset134(Set, S), PowerSet).
'''
+
+test_cases = [
+ ('powerset([], X)',
+ [{'X': '[[]]'}]),
+ ('powerset([1, 2], A), length(A, 4), lists:flatten(A, Y), msort(Y, X)',
+ [{'X': '[1, 1, 2, 2]'}]),
+ ('powerset([1, 2, 3], A), length(A, 8), lists:flatten(A, Y), msort(Y, X)',
+ [{'X': '[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/sets/powerset_2/sl.py b/prolog/problems/sets/powerset_2/sl.py
new file mode 100644
index 0000000..a782dee
--- /dev/null
+++ b/prolog/problems/sets/powerset_2/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'powerset/2'
+slug = 'Poišči potenčno množico od dane množice'
+
+description = '''\
+<p><code>powerset(Set, Powerset)</code>: množica <code>Powerset</code> vsebuje vse podmnožice od množice <code>Set</code>.</p>
+<pre>
+ ?- powerset([1,2,3], L).
+ L = [[1,2,3],[1,2],[1,3],[1],[2,3],[2],[3],[]].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/sets/subset_2/common.py b/prolog/problems/sets/subset_2/common.py
index 130d87b..f7d87d2 100644
--- a/prolog/problems/sets/subset_2/common.py
+++ b/prolog/problems/sets/subset_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 133
number = 40
visible = True
@@ -12,3 +16,50 @@ subset([H|T], [H|T1]) :-
subset([_|T], T1) :-
subset(T, T1).
'''
+
+test_cases = [
+ ('subset([], X)',
+ [{'X': '[]'}]),
+ ('subset([1, 3, 5, 7], A), msort(A, X)',
+ [{'X': '[]'}, {'X': '[7]'}, {'X': '[5]'}, {'X': '[5, 7]'}, {'X': '[3]'},
+ {'X': '[3, 7]'}, {'X': '[3, 5]'}, {'X': '[3, 5, 7]'}, {'X': '[1]'},
+ {'X': '[1, 7]'}, {'X': '[1, 5]'}, {'X': '[1, 5, 7]'}, {'X': '[1, 3]'},
+ {'X': '[1, 3, 7]'}, {'X': '[1, 3, 5]'}, {'X': '[1, 3, 5, 7]'}]),
+ ('subset([8, 4, 6, 2], A), msort(A, X)',
+ [{'X': '[]'}, {'X': '[2]'}, {'X': '[6]'}, {'X': '[2, 6]'}, {'X': '[4]'},
+ {'X': '[2, 4]'}, {'X': '[4, 6]'}, {'X': '[2, 4, 6]'}, {'X': '[8]'},
+ {'X': '[2, 8]'}, {'X': '[6, 8]'}, {'X': '[2, 6, 8]'}, {'X': '[4, 8]'},
+ {'X': '[2, 4, 8]'}, {'X': '[4, 6, 8]'}, {'X': '[2, 4, 6, 8]'}]),
+ ('subset([5, 6, 7, 0, 2], A), msort(A, X)',
+ [{'X': '[]'}, {'X': '[2]'}, {'X': '[0]'}, {'X': '[0, 2]'}, {'X': '[7]'},
+ {'X': '[2, 7]'}, {'X': '[0, 7]'}, {'X': '[0, 2, 7]'}, {'X': '[6]'},
+ {'X': '[2, 6]'}, {'X': '[0, 6]'}, {'X': '[0, 2, 6]'}, {'X': '[6, 7]'},
+ {'X': '[2, 6, 7]'}, {'X': '[0, 6, 7]'}, {'X': '[0, 2, 6, 7]'},
+ {'X': '[5]'}, {'X': '[2, 5]'}, {'X': '[0, 5]'}, {'X': '[0, 2, 5]'},
+ {'X': '[5, 7]'}, {'X': '[2, 5, 7]'}, {'X': '[0, 5, 7]'},
+ {'X': '[0, 2, 5, 7]'}, {'X': '[5, 6]'}, {'X': '[2, 5, 6]'},
+ {'X': '[0, 5, 6]'}, {'X': '[0, 2, 5, 6]'}, {'X': '[5, 6, 7]'},
+ {'X': '[2, 5, 6, 7]'}, {'X': '[0, 5, 6, 7]'}, {'X': '[0, 2, 5, 6, 7]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/sets/subset_2/sl.py b/prolog/problems/sets/subset_2/sl.py
new file mode 100644
index 0000000..eae4fcf
--- /dev/null
+++ b/prolog/problems/sets/subset_2/sl.py
@@ -0,0 +1,20 @@
+# coding=utf-8
+
+name = 'subset/2'
+slug = 'Generiraj vse podmnožice dane množice'
+
+description = '''\
+<p><code>subset(Set, Subset)</code>: množica <code>Subset</code> je podmnožica od <code>Set</code>. Ta predikat naj, eno po eno, generira vse veljavne podmnožice.</p>
+<pre>
+ ?- subset([1,2,3], SS).
+ SS = [1,2,3] ;
+ SS = [1,2] ;
+ SS = [1,3] ;
+ SS = [1] ;
+ SS = [2,3] ;
+ SS = [2] ;
+ SS = [3] ;
+ SS = [].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/sets/union_3/common.py b/prolog/problems/sets/union_3/common.py
index 506913a..ae24943 100644
--- a/prolog/problems/sets/union_3/common.py
+++ b/prolog/problems/sets/union_3/common.py
@@ -34,20 +34,15 @@ test_cases = [
[{'X': '[0, 1, 2, 3, 5, 6, 9]'}]),
]
-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:
- # Limit inferences for each solution to curb unbounded recursion.
- limited = 'call_with_inference_limit(({}), 100000, _)'.format(query)
- if prolog.engine.check_answers(engine_id, query=limited, answers=answers, timeout=1.0):
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
n_correct += 1
finally:
if engine_id:
diff --git a/prolog/problems/sets/union_3/sl.py b/prolog/problems/sets/union_3/sl.py
new file mode 100644
index 0000000..27d3088
--- /dev/null
+++ b/prolog/problems/sets/union_3/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'union/3'
+slug = 'Poišči unijo dveh množic'
+
+description = '''\
+<p><code>union(S1, S2, U)</code>: seznam <code>U</code> predstavlja unijo elementov v seznamih <code>S1</code> in <code>S2</code>, duplikatov (kot se za množice spodobi) ni.</p>
+<pre>
+ ?- union([1,5,2,3], [3,4,8,2], U).
+ U = [1,5,3,4,8,2].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/sorting/common.py b/prolog/problems/sorting/common.py
index f006f10..1ad1c8c 100644
--- a/prolog/problems/sorting/common.py
+++ b/prolog/problems/sorting/common.py
@@ -1,2 +1,4 @@
id = 3
number = 3
+
+allowed_groups = ['sorting', 'lists']
diff --git a/prolog/problems/sorting/is_sorted_1/common.py b/prolog/problems/sorting/is_sorted_1/common.py
index 8feb549..db5c3cc 100644
--- a/prolog/problems/sorting/is_sorted_1/common.py
+++ b/prolog/problems/sorting/is_sorted_1/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 121
number = 28
visible = True
@@ -12,3 +16,42 @@ is_sorted([H1,H2|T]) :-
H1 =< H2,
is_sorted([H2|T]).
'''
+
+test_cases = [
+ ('is_sorted([])',
+ [{}]),
+ ('is_sorted([5, 6, 13, 555, 2111, 2112])',
+ [{}]),
+ ('is_sorted([2, 5, 5, 13, 555, 2111, 2112])',
+ [{}]),
+ ('is_sorted([-2])',
+ [{}]),
+ ('is_sorted([-42, -42, -42, -42])',
+ [{}]),
+ ('\+ is_sorted([3, 4, 5, 6, 1, 2, 3])',
+ [{}]),
+ ('\+ is_sorted([3, 4, 5, 6, 1, 2, 3, 0])',
+ [{}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/sorting/is_sorted_1/sl.py b/prolog/problems/sorting/is_sorted_1/sl.py
new file mode 100644
index 0000000..5d4c1c5
--- /dev/null
+++ b/prolog/problems/sorting/is_sorted_1/sl.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+
+name = 'is_sorted/1'
+slug = 'Preveri, če so elementi seznama naraščajoče urejeni'
+
+description = '''\
+<p><code>is_sorted(L)</code>: elementi v seznamu <code>L</code> morajo biti urejeni v naraščajočem vrstnem redu.</p>
+<pre>
+ ?- is_sorted([2,3,6,8,12]).
+ true.
+ ?- is_sorted([2,3,1,6,5]).
+ false.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/sorting/isort_2/common.py b/prolog/problems/sorting/isort_2/common.py
index f2c4244..1669a4a 100644
--- a/prolog/problems/sorting/isort_2/common.py
+++ b/prolog/problems/sorting/isort_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 123
number = 30
visible = True
@@ -17,3 +21,36 @@ isort([H|T], SL) :-
isort(T, ST),
sins123(H, ST, SL).
'''
+
+test_cases = [
+ ('isort([], X)',
+ [{'X': '[]'}]),
+ ('isort([5, 3, 5, 5, 1, 2, 0], X)',
+ [{'X': '[0, 1, 2, 3, 5, 5, 5]'}]),
+ ('isort([2, 1, 3, 5, 6, 0, 22, 3], X)',
+ [{'X': '[0, 1, 2, 3, 3, 5, 6, 22]'}]),
+ ('isort([5, 4, 3, 2, 1], X)',
+ [{'X': '[1, 2, 3, 4, 5]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/sorting/isort_2/sl.py b/prolog/problems/sorting/isort_2/sl.py
new file mode 100644
index 0000000..79c3239
--- /dev/null
+++ b/prolog/problems/sorting/isort_2/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'isort/2'
+slug = 'Uredi seznam z uporabo urejanja z vstavljanjem'
+
+description = '''\
+<p><code>isort(L, SL)</code>: seznam <code>SL</code> vsebuje elemente iz seznama <code>L</code> urejene v naraščajočem vrstnem redu. Uporabi predikat <code>sins/3</code> za implementacijo urejanja z vstavljanjem.</p>
+<pre>
+ ?- isort([2,3,1,5,4], L).
+ L = [1,2,3,4,5].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/sorting/pivoting_4/common.py b/prolog/problems/sorting/pivoting_4/common.py
index dd1a1a9..3a3a906 100644
--- a/prolog/problems/sorting/pivoting_4/common.py
+++ b/prolog/problems/sorting/pivoting_4/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 124
number = 31
visible = True
@@ -14,3 +18,36 @@ pivoting(P, [H|T], S, [H|G]) :-
H > P,
pivoting(P, T, S, G).
'''
+
+test_cases = [
+ ('pivoting(5, [], A, B)',
+ [{'A': '[]', 'B': '[]'}]),
+ ('pivoting(5, [6, 7, 6], A, B)',
+ [{'A': '[]', 'B': '[6, 7, 6]'}]),
+ ('pivoting(4, [2, 1, 8, 9, 3, 4, 2], A, B)',
+ [{'A': '[2, 1, 3, 4, 2]', 'B': '[8, 9]'}]),
+ ('pivoting(4, [22, 1, 0, 8, 3, 5, 7, -2], A, B)',
+ [{'A': '[1, 0, 3, -2]', 'B': '[22, 8, 5, 7]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/sorting/pivoting_4/sl.py b/prolog/problems/sorting/pivoting_4/sl.py
new file mode 100644
index 0000000..b18e112
--- /dev/null
+++ b/prolog/problems/sorting/pivoting_4/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'pivoting/4'
+slug = 'Razdeli seznam na dva dela glede na podani element (pivot)'
+
+description = '''\
+<p><code>pivoting(P, L, S, G)</code>: seznam <code>S</code> vsebuje elemente iz <code>L</code> <em>manjše ali enake</em> <code>P</code>, seznam <code>G</code> pa elemente iz <code>L</code> <em>večje od</em> <code>P</code>. Vrstni red elementov v <code>S</code> in <code>G</code> naj bo enak kot v <code>L</code>.</p>
+<pre>
+ ?- pivoting(4, [1,4,5,8,6,4,2], S, G).
+ S = [1,4,4,2], G = [5,8,6].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/sorting/quick_sort_2/common.py b/prolog/problems/sorting/quick_sort_2/common.py
index 4afc8fa..d46c185 100644
--- a/prolog/problems/sorting/quick_sort_2/common.py
+++ b/prolog/problems/sorting/quick_sort_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 125
number = 32
visible = True
@@ -23,3 +27,36 @@ quick_sort([Pivot|T], Sorted) :-
quick_sort(Greater, SortedGreater),
conc125(SortedSmaller, [Pivot|SortedGreater], Sorted).
'''
+
+test_cases = [
+ ('quick_sort([], X)',
+ [{'X': '[]'}]),
+ ('quick_sort([5, 3, 5, 5, 1, 2, 0], X)',
+ [{'X': '[0, 1, 2, 3, 5, 5, 5]'}]),
+ ('quick_sort([2, 1, 3, 5, 6, 0, 22, 3], X)',
+ [{'X': '[0, 1, 2, 3, 3, 5, 6, 22]'}]),
+ ('quick_sort([5, 4, 3, 2, 1], X)',
+ [{'X': '[1, 2, 3, 4, 5]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/sorting/quick_sort_2/sl.py b/prolog/problems/sorting/quick_sort_2/sl.py
new file mode 100644
index 0000000..9611b46
--- /dev/null
+++ b/prolog/problems/sorting/quick_sort_2/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'quick_sort/2'
+slug = 'Uredi seznam z algoritmom quicksort'
+
+description = '''\
+<p><code>quick_sort(L, SL)</code>: seznam <code>SL</code> vsebuje elemente iz <code>L</code> urejene v naraščajočem vrstnem redu. Uporabi predikat <code>pivoting/4</code> za implementacijo algoritma quicksort.</p>
+<pre>
+ ?- quick_sort([2,3,1,5,4], L).
+ L = [1,2,3,4,5].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/sorting/sins_3/common.py b/prolog/problems/sorting/sins_3/common.py
index ab592ea..efc544e 100644
--- a/prolog/problems/sorting/sins_3/common.py
+++ b/prolog/problems/sorting/sins_3/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 122
number = 29
visible = True
@@ -13,3 +17,38 @@ sins(X, [Y|T], [Y|L]) :-
X > Y,
sins(X, T, L).
'''
+
+test_cases = [
+ ('sins(4, [], X)',
+ [{'X': '[4]'}]),
+ ('sins(4, [1, 2, 5, 6, 8], X)',
+ [{'X': '[1, 2, 4, 5, 6, 8]'}]),
+ ('sins(8, [1, 2, 3, 4, 5, 6, 7], X)',
+ [{'X': '[1, 2, 3, 4, 5, 6, 7, 8]'}]),
+ ('sins(1, [2, 3, 4, 5, 6, 7], X)',
+ [{'X': '[1, 2, 3, 4, 5, 6, 7]'}]),
+ ('sins(2, [2, 3, 4, 5, 6, 7], X)',
+ [{'X': '[2, 2, 3, 4, 5, 6, 7]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/sorting/sins_3/sl.py b/prolog/problems/sorting/sins_3/sl.py
new file mode 100644
index 0000000..22e51b2
--- /dev/null
+++ b/prolog/problems/sorting/sins_3/sl.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+
+name = 'sins/3'
+slug = 'Vstavi element na ustrezno mesto v urejen seznam'
+
+description = '''\
+<p><code>sins(X, SortedList, NewList)</code>: seznam <code>NewList</code> dobiš tako, da vstaviš element <code>X</code> v <code>SortedList</code> na ustrezno mesto tako, da ohraniš urejenost elementov.</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 = {}
diff --git a/prolog/problems/sorting/slowest_sort_ever_2/common.py b/prolog/problems/sorting/slowest_sort_ever_2/common.py
index fc8f980..5d0f566 100644
--- a/prolog/problems/sorting/slowest_sort_ever_2/common.py
+++ b/prolog/problems/sorting/slowest_sort_ever_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 126
number = 33
visible = True
@@ -24,3 +28,36 @@ slowest_sort_ever(L, S) :-
permute126(L, S),
is_sorted126(S).
'''
+
+test_cases = [
+ ('slowest_sort_ever([], X)',
+ [{'X': '[]'}]),
+ ('slowest_sort_ever([5, 3, 5, 1], X)',
+ [{'X': '[1, 3, 5, 5]'}]),
+ ('slowest_sort_ever([2, 1, 5, 6], X)',
+ [{'X': '[1, 2, 5, 6]'}]),
+ ('slowest_sort_ever([5, 4, 3, 2], X)',
+ [{'X': '[2, 3, 4, 5]'}]),
+]
+
+def test(code, aux_code):
+ n_correct = 0
+ engine_id = None
+ try:
+ 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:
+ if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0):
+ n_correct += 1
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/sorting/slowest_sort_ever_2/sl.py b/prolog/problems/sorting/slowest_sort_ever_2/sl.py
new file mode 100644
index 0000000..c62582c
--- /dev/null
+++ b/prolog/problems/sorting/slowest_sort_ever_2/sl.py
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+name = 'slowest_sort_ever/2'
+slug = 'Uredi seznam elementov s pomočjo naključnih permutacij'
+
+description = '''\
+<p><code>slowest_sort_ever(L, SL)</code>: seznam <code>SL</code> vsebuje elemente seznama <code>L</code> v naraščajočem vrstnem redu. Časovna zahtevnost algoritma naj bo O(n * n!).</p>
+<pre>
+ ?- slowest_sort_ever([2,3,1,5,4], L).
+ L = [1,2,3,4,5].
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/trees/common.py b/prolog/problems/trees/common.py
index a519878..d9ebca1 100644
--- a/prolog/problems/trees/common.py
+++ b/prolog/problems/trees/common.py
@@ -1,2 +1,4 @@
id = 6
number = 5
+
+allowed_groups = ['lists']
diff --git a/prolog/problems/trees/deletebt_3/common.py b/prolog/problems/trees/deletebt_3/common.py
index 98ad95f..52f9e3f 100644
--- a/prolog/problems/trees/deletebt_3/common.py
+++ b/prolog/problems/trees/deletebt_3/common.py
@@ -2,7 +2,7 @@
id = 137
number = 47
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/problems/trees/depthbt_2/common.py b/prolog/problems/trees/depthbt_2/common.py
index 85dfa27..4542419 100644
--- a/prolog/problems/trees/depthbt_2/common.py
+++ b/prolog/problems/trees/depthbt_2/common.py
@@ -2,7 +2,7 @@
id = 140
number = 45
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/problems/trees/insertbt_3/common.py b/prolog/problems/trees/insertbt_3/common.py
index f8ef004..eb1ea94 100644
--- a/prolog/problems/trees/insertbt_3/common.py
+++ b/prolog/problems/trees/insertbt_3/common.py
@@ -2,7 +2,7 @@
id = 138
number = 48
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/problems/trees/maxt_2/common.py b/prolog/problems/trees/maxt_2/common.py
index 280cb25..b1cdb39 100644
--- a/prolog/problems/trees/maxt_2/common.py
+++ b/prolog/problems/trees/maxt_2/common.py
@@ -2,7 +2,7 @@
id = 143
number = 50
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/problems/trees/memberbt_2/common.py b/prolog/problems/trees/memberbt_2/common.py
index f5e5435..6df89e3 100644
--- a/prolog/problems/trees/memberbt_2/common.py
+++ b/prolog/problems/trees/memberbt_2/common.py
@@ -2,7 +2,7 @@
id = 135
number = 42
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/problems/trees/membert_2/common.py b/prolog/problems/trees/membert_2/common.py
index c91371e..7d8f207 100644
--- a/prolog/problems/trees/membert_2/common.py
+++ b/prolog/problems/trees/membert_2/common.py
@@ -2,7 +2,7 @@
id = 142
number = 49
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/problems/trees/mirrorbt_2/common.py b/prolog/problems/trees/mirrorbt_2/common.py
index cc271cc..1ee0a9c 100644
--- a/prolog/problems/trees/mirrorbt_2/common.py
+++ b/prolog/problems/trees/mirrorbt_2/common.py
@@ -2,7 +2,7 @@
id = 136
number = 43
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/problems/trees/numberbt_2/common.py b/prolog/problems/trees/numberbt_2/common.py
index 7df71d8..e75075e 100644
--- a/prolog/problems/trees/numberbt_2/common.py
+++ b/prolog/problems/trees/numberbt_2/common.py
@@ -2,7 +2,7 @@
id = 139
number = 44
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/problems/trees/tolistbt_2/common.py b/prolog/problems/trees/tolistbt_2/common.py
index e6c8ffd..3c14c4e 100644
--- a/prolog/problems/trees/tolistbt_2/common.py
+++ b/prolog/problems/trees/tolistbt_2/common.py
@@ -2,7 +2,7 @@
id = 141
number = 46
-visible = True
+visible = False
facts = None
solution = '''\
diff --git a/prolog/sl.py b/prolog/sl.py
index 1de28ba..2bd2b56 100644
--- a/prolog/sl.py
+++ b/prolog/sl.py
@@ -26,4 +26,20 @@ hint = {
[%=messages%]
</pre>
''',
+
+ 'monkey_main': '''\
+<p>Uspelo mi je popraviti tvoj program. Napotki so prikazani v urejevalniku.</p>
+''',
+
+ 'monkey_change': '''\
+<p>Popravi ta cilj.</p>
+''',
+
+ 'monkey_insert': '''\
+<p>Dodaj novo pravilo oziroma cilj.</p>
+''',
+
+ 'monkey_remove': '''\
+<p>Odstrani ta cilj.</p>
+''',
}