summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--python/problems/functions/divisors/sl.py6
-rw-r--r--python/problems/functions/divisors_sum/sl.py6
-rw-r--r--python/problems/functions/friendly_numbers/sl.py6
-rw-r--r--python/problems/functions/perfect_numbers/sl.py6
-rw-r--r--python/problems/functions/prime_numbers/sl.py6
-rw-r--r--python/problems/functions/sl.py2
-rw-r--r--python/problems/functions_and_modules/all/sl.py6
-rw-r--r--python/problems/functions_and_modules/any/sl.py6
-rw-r--r--python/problems/functions_and_modules/caesar_cipher/sl.py6
-rw-r--r--python/problems/functions_and_modules/dominoes/sl.py6
-rw-r--r--python/problems/functions_and_modules/largest_sublist/sl.py6
-rw-r--r--python/problems/functions_and_modules/lists_sum/sl.py6
-rw-r--r--python/problems/functions_and_modules/map/sl.py6
-rw-r--r--python/problems/functions_and_modules/multiplicative_range/sl.py6
-rw-r--r--python/problems/functions_and_modules/sl.py2
-rw-r--r--python/problems/functions_and_modules/suspicious_words/sl.py6
-rw-r--r--python/problems/introduction/sl.py2
-rw-r--r--python/problems/lists_and_for/sl.py2
-rw-r--r--python/problems/while_and_if/sl.py2
-rw-r--r--readme.md221
-rw-r--r--robot/en.py42
-rw-r--r--robot/problems/introduction/circle20/common.py5
-rw-r--r--robot/problems/introduction/circle20/en.py24
-rw-r--r--robot/problems/introduction/circle20/sl.py12
-rw-r--r--robot/problems/introduction/countlines/common.py11
-rw-r--r--robot/problems/introduction/countlines/en.py27
-rw-r--r--robot/problems/introduction/countlines/naloga10_countLines.py3
-rw-r--r--robot/problems/introduction/countlines/sl.py13
-rw-r--r--robot/problems/introduction/en.py2
-rw-r--r--robot/problems/introduction/followline/common.py12
-rw-r--r--robot/problems/introduction/followline/en.py36
-rw-r--r--robot/problems/introduction/followline/naloga12_followLine.py3
-rw-r--r--robot/problems/introduction/followline/sl.py15
-rw-r--r--robot/problems/introduction/forward/common.py3
-rw-r--r--robot/problems/introduction/forward/en.py20
-rw-r--r--robot/problems/introduction/forward/sl.py10
-rw-r--r--robot/problems/introduction/forward1m/common.py3
-rw-r--r--robot/problems/introduction/forward1m/en.py23
-rw-r--r--robot/problems/introduction/forward1m/sl.py16
-rw-r--r--robot/problems/introduction/gyro90/common.py7
-rw-r--r--robot/problems/introduction/gyro90/sl.py11
-rw-r--r--robot/problems/introduction/gyrosquare/common.py24
-rw-r--r--robot/problems/introduction/gyrosquare/sl.py11
-rw-r--r--robot/problems/introduction/mindstorms_widgets_OLD.py1
-rw-r--r--robot/problems/introduction/printcolors/common.py4
-rw-r--r--robot/problems/introduction/printcolors/naloga09_printColors.py3
-rw-r--r--robot/problems/introduction/printcolors/sl.py13
-rw-r--r--robot/problems/introduction/rotateback/common.py3
-rw-r--r--robot/problems/introduction/rotateback/naloga11_rotateBack.py3
-rw-r--r--robot/problems/introduction/rotateback/sl.py12
-rw-r--r--robot/problems/introduction/sl.py2
-rw-r--r--robot/problems/introduction/spotturn90/common.py5
-rw-r--r--robot/problems/introduction/spotturn90/sl.py11
-rw-r--r--robot/problems/introduction/square20/common.py3
-rw-r--r--robot/problems/introduction/square20/sl.py11
-rw-r--r--robot/problems/introduction/wall1m/common.py7
-rw-r--r--robot/problems/introduction/wall1m/sl.py14
-rw-r--r--robot/sl.py2
195 files changed, 2346 insertions, 353 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>
+''',
}
diff --git a/python/problems/functions/divisors/sl.py b/python/problems/functions/divisors/sl.py
index 76b0917..f0e25c4 100644
--- a/python/problems/functions/divisors/sl.py
+++ b/python/problems/functions/divisors/sl.py
@@ -12,11 +12,7 @@ description = '''\
<p>
Napiši funkcijo <code>divisors(n)</code>, ki izpiše vse delitelje števila (brez samega sebe), ki ga vnese uporabnik.</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/functions/divisors_sum/sl.py b/python/problems/functions/divisors_sum/sl.py
index 47b8719..31cd369 100644
--- a/python/problems/functions/divisors_sum/sl.py
+++ b/python/problems/functions/divisors_sum/sl.py
@@ -13,11 +13,7 @@ description = '''\
Napiši funkcijo <code>divisors_sum(n)</code>, ki vrne vsoto vseh deliteljev števila, ki ga vnese uporabnik.
</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/functions/friendly_numbers/sl.py b/python/problems/functions/friendly_numbers/sl.py
index 51d47ae..dd15e0d 100644
--- a/python/problems/functions/friendly_numbers/sl.py
+++ b/python/problems/functions/friendly_numbers/sl.py
@@ -23,11 +23,7 @@ None
</p>
<p> Uporabite funkcijo za vsoto deliteljev!</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/functions/perfect_numbers/sl.py b/python/problems/functions/perfect_numbers/sl.py
index a354a17..156b41d 100644
--- a/python/problems/functions/perfect_numbers/sl.py
+++ b/python/problems/functions/perfect_numbers/sl.py
@@ -16,11 +16,7 @@ Primer popolnega števila je 28, saj so njegovi delitelji 1, 2, 4, 7, 14, njihov
</p>
<p> Uporabite funkcijo za vsoto deliteljev!</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/functions/prime_numbers/sl.py b/python/problems/functions/prime_numbers/sl.py
index f6c6b24..a224696 100644
--- a/python/problems/functions/prime_numbers/sl.py
+++ b/python/problems/functions/prime_numbers/sl.py
@@ -13,11 +13,7 @@ description = '''\
Napišite funkcijo <code>prime(n)</code>, ki izpiše vsa praštevila manjša od <code>n</code>.
</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/functions/sl.py b/python/problems/functions/sl.py
index e5f812d..7de0a40 100644
--- a/python/problems/functions/sl.py
+++ b/python/problems/functions/sl.py
@@ -1,3 +1,3 @@
name = 'Funkcije'
-description = 'Pisanje in uporaba funkcij'
+description = 'Pisanje in uporaba funkcij.'
diff --git a/python/problems/functions_and_modules/all/sl.py b/python/problems/functions_and_modules/all/sl.py
index f71fa4b..e224811 100644
--- a/python/problems/functions_and_modules/all/sl.py
+++ b/python/problems/functions_and_modules/all/sl.py
@@ -26,11 +26,7 @@ True
</pre>
</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/functions_and_modules/any/sl.py b/python/problems/functions_and_modules/any/sl.py
index f32e50e..ab1aacf 100644
--- a/python/problems/functions_and_modules/any/sl.py
+++ b/python/problems/functions_and_modules/any/sl.py
@@ -20,11 +20,7 @@ False
</pre>
</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/functions_and_modules/caesar_cipher/sl.py b/python/problems/functions_and_modules/caesar_cipher/sl.py
index ea4d9c8..bedf403 100644
--- a/python/problems/functions_and_modules/caesar_cipher/sl.py
+++ b/python/problems/functions_and_modules/caesar_cipher/sl.py
@@ -21,11 +21,7 @@ Predpostavite lahko, da niz <code>s</code> vsebuje le male črke angleške besed
</pre>
</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/functions_and_modules/dominoes/sl.py b/python/problems/functions_and_modules/dominoes/sl.py
index 41cb860..cfcee24 100644
--- a/python/problems/functions_and_modules/dominoes/sl.py
+++ b/python/problems/functions_and_modules/dominoes/sl.py
@@ -15,11 +15,7 @@ Vrsta domin je podana s seznamom parov (terk), na primer
ki prejme takšen seznam in pove, ali so domine pravilno zložene. Za prvi seznam mora vrniti <code>True</code> in za drugega <code>False</code>.
</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/functions_and_modules/largest_sublist/sl.py b/python/problems/functions_and_modules/largest_sublist/sl.py
index b550ce2..c3582f0 100644
--- a/python/problems/functions_and_modules/largest_sublist/sl.py
+++ b/python/problems/functions_and_modules/largest_sublist/sl.py
@@ -19,11 +19,7 @@ Napiši funkcijo <code>largest_sublist</code>, ki vrne podseznam z največjo vso
</pre>
</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/functions_and_modules/lists_sum/sl.py b/python/problems/functions_and_modules/lists_sum/sl.py
index 4baa002..88ac541 100644
--- a/python/problems/functions_and_modules/lists_sum/sl.py
+++ b/python/problems/functions_and_modules/lists_sum/sl.py
@@ -21,11 +21,7 @@ Za gornji seznam naj funkcija vrne seznam <code>[7, 4, 0, 10, 4]</code>, saj je,
</pre>
</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/functions_and_modules/map/sl.py b/python/problems/functions_and_modules/map/sl.py
index 18c47fb..6695b30 100644
--- a/python/problems/functions_and_modules/map/sl.py
+++ b/python/problems/functions_and_modules/map/sl.py
@@ -20,11 +20,7 @@ in vrne nov seznam <code>[f(x_1), f(x_2), ..., f(x_n)]</code>.
</pre>
</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/functions_and_modules/multiplicative_range/sl.py b/python/problems/functions_and_modules/multiplicative_range/sl.py
index 8bd4bd0..bb02a84 100644
--- a/python/problems/functions_and_modules/multiplicative_range/sl.py
+++ b/python/problems/functions_and_modules/multiplicative_range/sl.py
@@ -18,11 +18,7 @@ Napišite funkcijo <code>mrange(start, factor, length)</code>, ki vrne seznam, k
</pre>
</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/functions_and_modules/sl.py b/python/problems/functions_and_modules/sl.py
index fb4f520..e4321ec 100644
--- a/python/problems/functions_and_modules/sl.py
+++ b/python/problems/functions_and_modules/sl.py
@@ -1,3 +1,3 @@
name = 'Funkcije in delo z moduli'
-description = 'Uporaba funkcij in delo z moduli (predvsem z nizi)'
+description = 'Uporaba funkcij in delo z moduli (predvsem z nizi).'
diff --git a/python/problems/functions_and_modules/suspicious_words/sl.py b/python/problems/functions_and_modules/suspicious_words/sl.py
index 3bf2c7b..1aa3bdf 100644
--- a/python/problems/functions_and_modules/suspicious_words/sl.py
+++ b/python/problems/functions_and_modules/suspicious_words/sl.py
@@ -18,11 +18,7 @@ Beseda je sumljiva, če vsebuje tako črko u kot črko a.
</pre>
</p>'''
-plan = ['''\
-<p></p>
-''',
- '''\
-<p></p>''']
+plan = []
hint = {
'final_hint': ['''\
diff --git a/python/problems/introduction/sl.py b/python/problems/introduction/sl.py
index 3141ece..403c941 100644
--- a/python/problems/introduction/sl.py
+++ b/python/problems/introduction/sl.py
@@ -1,3 +1,3 @@
name = 'Uvod'
-description = 'Izrazi, spremenljivke, funkcije, prvi program'
+description = 'Izrazi, spremenljivke, funkcije, prvi program.'
diff --git a/python/problems/lists_and_for/sl.py b/python/problems/lists_and_for/sl.py
index d9c38e9..361f1f0 100644
--- a/python/problems/lists_and_for/sl.py
+++ b/python/problems/lists_and_for/sl.py
@@ -1,2 +1,2 @@
name = 'Seznami in zanka for'
-description = 'Seznami, terke, zanka for' \ No newline at end of file
+description = 'Seznami, terke, zanka for.'
diff --git a/python/problems/while_and_if/sl.py b/python/problems/while_and_if/sl.py
index 3d037b8..fbb177a 100644
--- a/python/problems/while_and_if/sl.py
+++ b/python/problems/while_and_if/sl.py
@@ -1,2 +1,2 @@
name = 'Pogojni stavki in zanke'
-description = 'Logični izrazi, pogojni stavek if-else, zanka while'
+description = 'Logični izrazi, pogojni stavek if-else, zanka while.'
diff --git a/readme.md b/readme.md
index ec26acd..420120d 100644
--- a/readme.md
+++ b/readme.md
@@ -1,20 +1,20 @@
+Directory structure
+===================
+
The file hierarchy for problem data is below. Comments indicate the global
variables and functions that can be defined in each file. Only the ID is
-necessary. See existing problems for examples.
-
-<language>
-├── common.py # id, hint_type, hint() [language-specific]
-├── en.py # name, description, hint [language-specific]
-├── sl.py # name, description, hint [language-specific]
-└── problems
-    └── <group>
- ├── common.py # id, number
- ├── en.py # name, description
- ├── sl.py # name, description
-    └── <problem>
-       ├── common.py # id, number, test(), hint_type, hint() [problem-specific]
-       ├── en.py # name, plan, hint [problem-specific]
-       └── sl.py # name, plan, hint [problem-specific]
+required.
+
+ <language>
+ ├── common.py # id, hint_type, hint() [language-specific]
+ ├── en.py # name, description, hint [language-specific]
+ └── problems
+    └── <group>
+ ├── common.py # id, number
+ ├── en.py # name, description
+    └── <problem>
+       ├── common.py # id, number, test(), hint_type, hint() [problem-specific]
+       └── en.py # name, plan, hint [problem-specific]
To add a problem, create the necessary files. Pick an unused problem ID from
the relevant range below:
@@ -23,6 +23,191 @@ the relevant range below:
Python: 20000-29999
Robot: 30000-39999
-Running scripts/build_web_resources.py in the codeq-server repo will generate
-JSON files for all problems, and insert new problems, groups and languages in
-the database.
+Running `scripts/build\_web\_resources.py` in the codeq-server repo
+will generate JSON files for all problems, and insert new problems, groups and
+languages in the database.
+
+
+Hints
+=====
+
+There are two distinct hint types: normal hints and popup hints. Normal hint
+appears in the hints section of the application, and contains a single or
+multipart message. A popup hint highlights a range of user’s code and displays
+a message when the user clicks on or hovers over the highlight. The type of
+each hint is defined in the appropriate `common.py` file, like this:
+
+ # common.py
+ from server.hints import Hint, HintPopup
+ hint_type = {
+ 'normal_1': Hint('normal_1'),
+ 'normal_2': Hint('normal_2'),
+ 'popup': Hint('popup')
+ }
+
+Message for each hint is defined in the `hint` dictionary in the corresponding
+language file (e.g. `en.py`). For the example above:
+
+ # en.py
+ hint = {
+ 'normal_1': '<p>Message for hint "normal_1".</p>',
+ 'normal_2': [
+ '<p>First part.</p>',
+ {'message': '<p>Second part.</p>', 'linkText': 'Details…'},
+ '<p>Final part.</p>'
+ ],
+ 'popup': '<p>There is an error here.</p>'
+ }
+
+For a popup hint, a single string is required and will be displayed when the
+user hovers over (or clicks on) the highlighted range. For a normal hint, a
+single string can be specified which will be displayed in the hints section
+(e.g. `normal\_1`).
+
+Multipart hints
+---------------
+
+Instead of specifying a single string for a normal hint, a list of strings can
+be given; initially, only the first string will be displayed, with a “More…”
+link to show the next string and so on. List elements can also be dictionaries
+with `message` and `linkText` attributes - in this case, “More…” will be
+replaced by the value of `linkText`.
+
+In the above example, on receiving the `normal\_2` hint, application will first
+show
+
+ First part.
+ More…
+
+After clicking “More…”, the message is extended:
+
+ First part.
+ Second part.
+ Details…
+
+After clicking “Details…”, the message is extended again:
+
+ First part.
+ Second part.
+ Final part.
+
+Template arguments
+------------------
+
+A template in the form `[%=arg%]` may appear in any hint string. It
+will be replaced with an actual value returned by the `hint` or
+`test` functions (described in the next section). This is used for
+example when displaying test results, with the hint defined as
+
+ 'test_results': '<p>Your code passed [%=passed%] / [%=total%] tests.</p>'
+
+The actual values for the `passed` and `total` arguments
+are returned by the `test` function.
+
+
+Problem functions
+=================
+
+For each problem, a `test(program)` and `hint(program)` functions must be
+specified in the corresponding `common.py` file. They are called with the
+user’s current program when the Test or Hint button is pressed.
+
+The `hint(program)` function should return a list of hint objects. Each hint
+object is a dictionary containing the hint ID, any arguments for the hint
+message, and (for popup hints) `start` and `end` attributes indicating the
+range of code to highlight.
+
+The `test(program)` function should return a pair of values `(correct, hints)`,
+where `correct` is a Boolean value indicating whether the program is correct,
+and `hints` a list of hint objects as described above.
+
+For example, given an incorrect program the `test` function might return
+
+ (False, [{'id': 'test_results', 'args': {'passed': 2, 'total': 5}}])
+
+saying that the program passed two out of five tests, while the `hint` function
+might return
+
+ [{'id': 'normal_1'},
+ {'id': 'popup', 'start': 14, 'end': 20}]
+
+displaying the message for `normal\_1` hint in the hints window and
+highlighting the code between characters 14 and 20.
+
+
+Example
+=======
+
+In this section we add a new problem “Ballistics” in the “Introduction” section
+for the “Python” course. First, create the required directory structure (note
+the required “problems/” path component):
+
+ mkdir -p "python/problems/introduction/ballistics"
+
+Course, group and problem definitions are given in “common.py” files in the
+respective directories. The “en.py” file in the same directory stores the
+English versions of user messages. Additional language files can be created to
+support more languages.
+
+Course files
+------------
+
+### python/common.py
+
+Minimum content:
+
+ from server.hints import Hint
+
+ id = <course id>
+ hint_type = {
+ 'no_hint': Hint('no_hint'),
+ 'test_results': Hint('test_results'),
+ }
+
+The id attribute stores ID of the corresponding database row and must be
+different from existing courses.
+
+### python/en.py
+
+ name = 'Python'
+ description = 'Introductory Python course'
+
+ hint = {
+ 'no_hint': '<p>No hint available, sorry!</p>',
+ 'test_results': '<p>Your code passed [%=passed%] / [%=total%] tests.</p>',
+ }
+
+Group files
+-----------
+
+### python/problems/introduction/common.py
+
+Minimum content:
+
+ id = <group id>
+ number = 1
+
+The number attributes are used to determine the order of groups in a course (in
+this case, “Introduction” is the first problem group in the “Python” course).
+
+### python/problems/introduction/en.py
+
+ name = 'Introduction'
+ description = 'Expressions, variables, functions, first program.'
+
+Problem files
+-------------
+
+ id = <problem id>
+ number = 3
+ visible = True
+
+ solution = '''\
+ from math import *
+ g = 9.8
+ kot = float(input("Vnesi kot (v stopinjah): "))
+ v = float(input("Vnesi hitrost (v m/s): "))
+ kot_rad = kot * 2 * pi / 360
+ razdalja = v ** 2 * sin(2 * kot_rad) / g
+ print("Kroglo bo odneslo", razdalja, "metrov.")
+ '''
diff --git a/robot/en.py b/robot/en.py
index f296516..61314e9 100644
--- a/robot/en.py
+++ b/robot/en.py
@@ -3,5 +3,47 @@
name = 'Robot'
description = 'Introductory Robot course.'
+
hint = {
+ 'init':['''<p>In code the robot is represented by mindstorms_widgets(): <code>robot = mindstorms_widgets()</code>.</p>'''],
+ 'connectMotorLeft':['''<p>Connect the left motor to the robot.</p>''',
+ '''<p><code>robot.connect_motor( 'left' )</code>.</p>'''],
+ 'connectMotorRight':['''<p>Connect the right motor to the robot.</p>''',
+ '''<p><code>robot.connect_motor( 'right' )</code>.</p>'''],
+ 'moveSteering':['''<p>Synchronize the motors.</p>''',
+ '''<p>Use move_steering method for synchonization <code>robot.move_steering( ... )</code>.</p>'''],
+ 'moveSteeringOff':['''<p>Stop the motors.</p>''',
+ '''<p><code>robot.move_steering( 'off' )</code>.</p>'''],
+ 'onForSeconds':['''<p>The first argument of <code>robot.move_steering</code> should specify that the motors will run for a certain amount of time.</p>''',
+ '''<p><code>robot.move_steering('on_for_seconds', ... )</code>.</p>'''],
+ 'direction':['''<p>Define the direction of moving; negative/positive values represent a left/right turn.</p>'''],
+ 'seconds':['''<p>Determine the running time of the motors.</p>'''],
+ 'connectColorSensor':['''<p>Connect the color sensor to the robot.</p>''',
+ '''<p><code>robot.connect_sensor( 'color' )</code>.</p>'''],
+ 'colorSensorMeasure':['''<p>While the robot is moving forward, it should use the color sensor in 'color' mode to recognize the colors.</p>''',
+ '''<p><code>robot.color_sensor_measure( 'color' )</code>.</p>'''],
+ 'colorSensorMeasureRLI':['''<p>Use the color sensor in 'reflected_light_intensity' mode.</p>''',
+ '''<p><code>robot.color_sensor_measure( 'reflected_light_intensity' )</code>.</p>'''],
+ 'moveTankOn':['''<p>Use the method for separate motor control, to set each motor's power separately.</p>''',
+ '''<p>The most appropriate for this is <code>robot.move_tank( ... )</code>.</p>''',
+ '''<p><code>robot.move_tank( 'on', ...)</code></p>'''],
+ 'lrPower': ['''<p>Set the powers of the left and right motor.</p>''',
+ '''<p><code>robot.move_tank( 'on', lr_power=[ ... ])</code></p>'''],
+ 'moveTankOff': ['''Stop the robot.''',
+ '''<p><code>robot.move_tank( 'off' )</code></p>'''],
+ 'onForRotations':['''<p>Set the first argument of <code>robot.move_steering</code> method so that the motors will run for the specified number of rotations.</p>''',
+ '''<p><code>robot.move_steering('on_for_rotations', ... )</code>.</p>'''],
+ 'rotations':['''<p>Determine the number of rotations; how many turns should the motors do in a meter? Measure the circumference of the wheel and compute the number of rotations per meter.</p>''',
+ '''<p><code>robot.move_steering( 'on_for_rotations', direction=0, rotations=5 )</code>.</p>'''],
+ 'no_hint': ['''\
+<p>No hint here!</p>
+'''],
+
+ 'system_error': ['''\
+<p><span style="color: red;">System error:</span> [%=message%].</p>
+'''],
+
+ 'test_results': ['''\
+<p>Your program passed [%=passed%] / [%=total%] tests.</p>
+'''],
}
diff --git a/robot/problems/introduction/circle20/common.py b/robot/problems/introduction/circle20/common.py
index 879f198..4d283d0 100644
--- a/robot/problems/introduction/circle20/common.py
+++ b/robot/problems/introduction/circle20/common.py
@@ -10,14 +10,11 @@ number = 5
visible = True
solution = '''\
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
-
robot = mindstorms_widgets()
robot.connect_motor( 'left' )
robot.connect_motor( 'right' )
-fct = 9 # full circle time
+fct = 8.9 # full circle time
rad = 20 # Direction to make a good radius for the circle
robot.move_steering( 'on_for_seconds', direction=rad, power=40, seconds=fct )
'''
diff --git a/robot/problems/introduction/circle20/en.py b/robot/problems/introduction/circle20/en.py
index 8210d71..d2c410c 100644
--- a/robot/problems/introduction/circle20/en.py
+++ b/robot/problems/introduction/circle20/en.py
@@ -1,14 +1,32 @@
# coding=utf-8
import server
-mod = server.problems.load_language('python', 'en')
+mod = server.problems.load_language('robot', 'en')
id = 205
name = 'Circle 20 cm'
slug = 'Circle 20 cm'
description = '''\
-'''
+<p>Write a program that will make the robot drive in circle (r=20cm) and stop after one loop.</p>'''
hint = {
-
+ 'mW_init':mod.hint['init'],
+ 'connectMotorLeft':mod.hint['connectMotorLeft'],
+ 'connectMotorRight':mod.hint['connectMotorRight'],
+ 'moveSteering':mod.hint['moveSteering'],
+ 'onForSeconds':mod.hint['onForSeconds'],
+ 'direction':mod.hint['direction']+['''<p>The value of this parameter should be such that would make the robot circle with radius 20cm. This value highly depends on the construction of the robot.</p>''',
+ '''<p><code>robot.move_steering( 'on_for_seconds', direction=20, ... )</code>.</p>'''],
+ 'seconds':mod.hint['seconds']+['''<p>Experimentally determine the time (in seconds) the robot needs for one loop.</p>''',
+ '''<p><code>robot.move_steering( 'on_for_seconds', direction=0, seconds=3 )</code>.</p>'''],
}
+
+plan = ['''\
+<p>The program should:</p>
+<ol>
+ <li>create a mindstorms_widgets() object, which represents the robot in your code.</li>
+ <li>connect the driving motors.</li>
+ <li>calculate the turn so that the robot would drive in circle with radius 20 cm.</li>
+ <li>synchronize the motors and run them for a specified time, so that the robot stops after one round.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/circle20/sl.py b/robot/problems/introduction/circle20/sl.py
index 219f9c7..735458a 100644
--- a/robot/problems/introduction/circle20/sl.py
+++ b/robot/problems/introduction/circle20/sl.py
@@ -13,7 +13,7 @@ hint = {
'''<p><code>robot.connect_motor( 'left' )</code>.</p>'''],
'connectMotorRight':['''<p>Robotu priključi desni motor</p>''',
'''<p><code>robot.connect_motor( 'right' )</code>.</p>'''],
- 'moveSteering':['''<p>Sinhroniziraj motorja in ju zaženi za 3 sekunde.</p>''',
+ 'moveSteering':['''<p>Sinhroniziraj motorja.</p>''',
'''<p>Za sinhronizirano vožnjo je najbolj primerna metoda <code>robot.move_steering( ... )</code>.</p>'''],
'onForSeconds':['''<p>Prvi argument metode <code>robot.move_steering</code> naj pove, da bo delovanje motorjev časovno omejeno.</p>''',
'''<p><code>robot.move_steering('on_for_seconds', ... )</code>.</p>'''],
@@ -24,3 +24,13 @@ hint = {
'''<p>Za dani polmer izmeri čas, ki ga robot potrebuje za en obhod.</p>''',
'''<p><code>robot.move_steering( 'on_for_seconds', direction=0, seconds=3 )</code>.</p>'''],
}
+
+plan = ['''\
+<p>Program izvedemo v naslednjih korakih:</p>
+<ol>
+ <li>Naredimo objekt mindstorms_widgets(), s katerim predstavimo robota.</li>
+ <li>Nanj povežemo oba pogonska motorja.</li>
+ <li>Izračunamo ostrino zavoja, pri kateri bo robot vozil po krogu s polmerom 20 cm.</li>
+ <li>Sinhronizirano poženemo oba motorja za premik v izračunani smeri in časovno omejimo na en obhod.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/countlines/common.py b/robot/problems/introduction/countlines/common.py
index 5b8db2e..bf5343b 100644
--- a/robot/problems/introduction/countlines/common.py
+++ b/robot/problems/introduction/countlines/common.py
@@ -11,8 +11,6 @@ visible = True
solution = '''\
import time
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
color_table = ['none', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown']
@@ -23,16 +21,17 @@ robot.connect_sensor( 'color' )
robot.move_steering( 'on' )
start = time.time()
-stevec = 0
+counter = 0
color = -1
-while time.time()-start < 2.1:
+while time.time()-start < 1.2:
c = robot.color_sensor_measure( 'color' ) # values: 0-7 see the scale above
if c!=color:
if c!=6 and c!=0:
- stevec += 1
+ counter += 1
color = c
robot.move_steering( 'off' )
-print( "Stevilo crt:", stevec )
+
+print( "Number of lines:", counter )
'''
hint_type = {
diff --git a/robot/problems/introduction/countlines/en.py b/robot/problems/introduction/countlines/en.py
index 8b3b275..7655b21 100644
--- a/robot/problems/introduction/countlines/en.py
+++ b/robot/problems/introduction/countlines/en.py
@@ -1,14 +1,37 @@
# coding=utf-8
import server
-mod = server.problems.load_language('python', 'en')
+mod = server.problems.load_language('robot', 'en')
id = 206
name = 'Count lines'
slug = 'Count lines'
description = '''\
+ Write a program to count the color lines on white background using the robot with a color sensor. The robot should drive forward, crossing the lines and count them.
'''
hint = {
-
+ 'mW_init':mod.hint['init'],
+ 'connectMotorLeft':mod.hint['connectMotorLeft'],
+ 'connectMotorRight':mod.hint['connectMotorRight'],
+ 'moveSteeringOn':mod.hint['moveSteering']+['''<p>Use move_steering method with 'on' as the first parameter <code>robot.move_steering( 'on',... )</code>.</p>'''],
+ 'moveSteeringOff':mod.hint['moveSteeringOff'],
+ 'connectColorSensor':mod.hint['connectColorSensor'],
+ 'colorSensorMeasure':mod.hint['colorSensorMeasure'],
+ 'while':['''<p>Use the while loop: inside, the robot should read the current color and increase the counter when the color changes.</p>''',
+ '''<p>Interrupt the loop after a certain amount of time; determine the time the robot needs to drive over all the colors experimentally; use <code>time.time()</code>.</p>''',
+ '''<p><code>while time.time()-start < 1.5:</code>.</p>'''],
}
+
+plan = ['''\
+<p>The program should:</p>
+<ol>
+ <li>create a mindstorms_widgets() object, which represents the robot in your code.</li>
+ <li>connect the driving motors.</li>
+ <li>connect the color sensor.</li>
+ <li>synchronize the motors and run them so that the robot would move forward.</li>
+ <li>inside the loop, let the robot recognize colors and increase the counter.</li>
+ <li>interrupt the loop after a certain amount of time.</li>
+ <li>stop the motors.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/countlines/naloga10_countLines.py b/robot/problems/introduction/countlines/naloga10_countLines.py
index d1a8326..7079f7c 100644
--- a/robot/problems/introduction/countlines/naloga10_countLines.py
+++ b/robot/problems/introduction/countlines/naloga10_countLines.py
@@ -7,8 +7,7 @@ Naloga 10:
"""
import time
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
+from mindstorms_widgets import *
color_table = ['none', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown']
diff --git a/robot/problems/introduction/countlines/sl.py b/robot/problems/introduction/countlines/sl.py
index 4e1c3d4..1f8ea18 100644
--- a/robot/problems/introduction/countlines/sl.py
+++ b/robot/problems/introduction/countlines/sl.py
@@ -24,3 +24,16 @@ hint = {
'''<p>Zanka je lahko časovno omejena, npr. z uporabo metode <code>time.time()</code>.</p>''',
'''<p><code>while time.time()-start < 1.1:</code>.</p>'''],
}
+
+plan = ['''\
+<p>Program izvedemo v naslednjih korakih:</p>
+<ol>
+ <li>Naredimo objekt mindstorms_widgets(), s katerim predstavimo robota.</li>
+ <li>Nanj povežemo oba pogonska motorja.</li>
+ <li>Povežemo barvni senzor.</li>
+ <li>Vklopimo oba motorja tako, da robot vozi naravnost.</li>
+ <li>V zanki naj robot bere barve in jih šteje.</li>
+ <li>Zanka naj se konča po vnaprej določenem času, npr. 3 sekunde.</li>
+ <li>Ustavimo oba motorja.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/en.py b/robot/problems/introduction/en.py
new file mode 100644
index 0000000..5236b4e
--- /dev/null
+++ b/robot/problems/introduction/en.py
@@ -0,0 +1,2 @@
+name = 'Introduction'
+description = 'Motors and sensors.'
diff --git a/robot/problems/introduction/followline/common.py b/robot/problems/introduction/followline/common.py
index 3e84cd4..e28ca35 100644
--- a/robot/problems/introduction/followline/common.py
+++ b/robot/problems/introduction/followline/common.py
@@ -11,8 +11,6 @@ visible = True
solution = '''\
import time
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
robot = mindstorms_widgets()
robot.connect_motor( 'left' )
@@ -21,10 +19,10 @@ robot.connect_sensor( 'color' )
start = time.time()
while time.time()-start < 10:
- if robot.color_sensor_measure('reflected_light_intensity') < 30:
- L, R = 0, 20
+ if robot.color_sensor_measure('reflected_light_intensity') < 50:
+ L, R = 0, 30
else:
- L, R = 20, 0
+ L, R = 30, 0
robot.move_tank( 'on', lr_power=[L,R])
robot.move_tank( 'off' )
'''
@@ -61,13 +59,13 @@ def hint( code):
if not (has_token_sequence(tokens, ['connect_sensor', '(' ]) and 'color' in code):
return [{'id': 'connectColorSensor'}]
- if not (has_token_sequence(tokens, ['move_steering', '(']) and 'on' in code):
+ if not (has_token_sequence(tokens, ['move_tank', '(']) and 'on' in code):
return [{'id': 'moveTankOn'}]
if not 'lr_power' in code:
return [{'id': 'lrPower'}]
- if not (has_token_sequence(tokens, ['move_steering', '(']) and 'off' in code):
+ if not (has_token_sequence(tokens, ['move_tank', '(']) and 'off' in code):
return [{'id': 'moveTankOff'}]
if not (has_token_sequence(tokens, ['color_sensor_measure', '(']) and 'reflected_light_intensity' in code):
diff --git a/robot/problems/introduction/followline/en.py b/robot/problems/introduction/followline/en.py
index 3f816fe..9a588bc 100644
--- a/robot/problems/introduction/followline/en.py
+++ b/robot/problems/introduction/followline/en.py
@@ -1,14 +1,46 @@
# coding=utf-8
import server
-mod = server.problems.load_language('python', 'en')
+mod = server.problems.load_language('robot', 'en')
id = 207
name = 'Line following'
slug = 'Line following'
description = '''\
+ Write the program for line following. The robot should use the color sensor to follow the black line on white background.
'''
hint = {
-
+ 'mW_init':mod.hint['init'],
+ 'connectMotorLeft':mod.hint['connectMotorLeft'],
+ 'connectMotorRight':mod.hint['connectMotorRight'],
+ 'moveSteeringOn':mod.hint['moveSteering']+['''<p>Use move_steering method with 'on' as the first parameter <code>robot.move_steering( 'on',... )</code>.</p>'''],
+ 'moveSteeringOff':mod.hint['moveSteeringOff'],
+ 'connectColorSensor':mod.hint['connectColorSensor'],
+ 'colorSensorMeasureRLI':mod.hint['colorSensorMeasureRLI'],
+ 'while':['''<p>Use the loop, inside which the robot would follow the line.</p>''',
+ '''<p>The loop should be time constrained, e.g. <code>time.time()</code>.</p>''',
+ '''<p><code>start = time.time()\nwhile time.time()-start < 10:</code>.</p>'''],
+ 'moveTankOn':mod.hint['moveTankOn'],
+ 'lrPower': mod.hint['lrPower'],
+ 'moveTankOff': mod.hint['moveTankOff'],
+ 'time': ['''Use time() to measure time.''',
+ '''<p><code>start = time.time()\nwhile time.time()-start < 10:</code></p>'''],
+ 'if': ['''<p>Use conditional statement inside the loop...</p>''',
+ '''<p>If the robot sees the line, it should turn slightly to go off the line; if the robot sees the background, it should turn towards the line.</p>''']
}
+
+plan = ['''\
+<p>The program should do the following:</p>
+<ol>
+ <li>create a mindstorms_widgets() object, which represents the robot in your code.</li>
+ <li>connect the driving motors.</li>
+ <li>connect the color sensor.</li>
+ <li>in a loop, the robot should read the color sensor to check whether it is on or off line.</li>
+ <li>if it sees black, it should turn right/left; if it sees white, it should turn left/right.</li>
+ <li>break the loop after specified time, 10 seconds.</li>
+ <li>stop the motors.</li>
+</ol>
+<p>Note: you may need to calibrate the color sensor before running the program on the robot.</p>
+'''
+]
diff --git a/robot/problems/introduction/followline/naloga12_followLine.py b/robot/problems/introduction/followline/naloga12_followLine.py
index 347e89e..e6e19a0 100644
--- a/robot/problems/introduction/followline/naloga12_followLine.py
+++ b/robot/problems/introduction/followline/naloga12_followLine.py
@@ -8,8 +8,7 @@ Naloga 12:
import sys
sys.path.append('/home/user/codeq')
import time
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
+from mindstorms_widgets import *
robot = mindstorms_widgets()
robot.connect_motor( 'left' )
diff --git a/robot/problems/introduction/followline/sl.py b/robot/problems/introduction/followline/sl.py
index 848fe2b..cdc6e19 100644
--- a/robot/problems/introduction/followline/sl.py
+++ b/robot/problems/introduction/followline/sl.py
@@ -32,3 +32,18 @@ hint = {
'if': ['''<p>V zanki uporabi pogojni stavek...</p>''',
'''<p>Če robot vidi črto, naj zavije z nje; če vidi podlago, naj zavije proti črti.</p>''']
}
+
+plan = ['''\
+<p>Program izvedemo v naslednjih korakih:</p>
+<ol>
+ <li>Naredimo objekt mindstorms_widgets(), s katerim predstavimo robota.</li>
+ <li>Nanj povežemo oba pogonska motorja.</li>
+ <li>Povežemo barvni senzor.</li>
+ <li>V zanki preverjamo, kakšno barvo vidi robot s senzorjem.</li>
+ <li>Če vidi črno, naj zavije desno, če vidi belo, naj zavije levo. (Sledi desnemu robu črte).</li>
+ <li>Zanka naj se konča po vnaprej določenem času, 10 sekund.</li>
+ <li>Ustavimo oba motorja.</li>
+</ol>
+<p>Opomba: potrebna je predhodna kalibracija barvnega senzorja.</p>
+'''
+]
diff --git a/robot/problems/introduction/forward/common.py b/robot/problems/introduction/forward/common.py
index 5a46d86..0793d72 100644
--- a/robot/problems/introduction/forward/common.py
+++ b/robot/problems/introduction/forward/common.py
@@ -9,9 +9,6 @@ number = 1
visible = True
solution = '''\
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
-
robot = mindstorms_widgets()
robot.connect_motor( 'left' )
robot.connect_motor( 'right' )
diff --git a/robot/problems/introduction/forward/en.py b/robot/problems/introduction/forward/en.py
index be73921..400c452 100644
--- a/robot/problems/introduction/forward/en.py
+++ b/robot/problems/introduction/forward/en.py
@@ -1,5 +1,8 @@
# coding=utf-8
+import server
+mod = server.problems.load_language('robot', 'en')
+
name = 'Forward 3s'
slug = 'Forward 3s'
@@ -8,5 +11,20 @@ description = '''\
'''
hint = {
-
+ 'mW_init':mod.hint['init'],
+ 'connectMotorLeft':mod.hint['connectMotorLeft'],
+ 'connectMotorRight':mod.hint['connectMotorRight'],
+ 'moveSteering':mod.hint['moveSteering'],
+ 'onForSeconds':mod.hint['onForSeconds'],
+ 'direction':mod.hint['direction']+['''<p><code>robot.move_steering( 'on_for_seconds', direction=0, ... )</code>.</p>'''],
+ 'seconds':mod.hint['seconds']+['''<p><code>robot.move_steering( 'on_for_seconds', direction=0, seconds=3 )</code>.</p>'''],
}
+
+plan = ['''\
+<p>The program should:</p>
+<ol>
+ <li>create a mindstorms_widgets() object, which represents the robot in your code.</li>
+ <li>connect the driving motors.</li>
+ <li>synchronize the motors and run them so that the robot would move forward for 3 seconds.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/forward/sl.py b/robot/problems/introduction/forward/sl.py
index a6f7e86..cd9b096 100644
--- a/robot/problems/introduction/forward/sl.py
+++ b/robot/problems/introduction/forward/sl.py
@@ -21,3 +21,13 @@ hint = {
'seconds':['''<p>Napiši časovno omejitev v sekundah.</p>''',
'''<p><code>robot.move_steering( 'on_for_seconds', direction=0, seconds=3 )</code>.</p>'''],
}
+
+plan = ['''\
+<p>Program izvedemo v naslednjih korakih:</p>
+<ol>
+ <li>Naredimo objekt mindstorms_widgets(), s katerim predstavimo robota.</li>
+ <li>Nanj povežemo oba pogonska motorja.</li>
+ <li>Vklopimo oba motorja v sinhronem načinu tako, da robot vozi naravnost.</li>
+ <li>Določimo čas trajanja vožnje 3 sekunde.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/forward1m/common.py b/robot/problems/introduction/forward1m/common.py
index a8dd9ad..201a981 100644
--- a/robot/problems/introduction/forward1m/common.py
+++ b/robot/problems/introduction/forward1m/common.py
@@ -10,9 +10,6 @@ number = 2
visible = True
solution = '''\
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
-
robot = mindstorms_widgets()
robot.connect_motor( 'left' )
robot.connect_motor( 'right' )
diff --git a/robot/problems/introduction/forward1m/en.py b/robot/problems/introduction/forward1m/en.py
index bdf2a45..f47d088 100644
--- a/robot/problems/introduction/forward1m/en.py
+++ b/robot/problems/introduction/forward1m/en.py
@@ -1,15 +1,32 @@
# coding=utf-8
import server
-mod = server.problems.load_language('python', 'en')
+mod = server.problems.load_language('robot', 'en')
id = 208
name = 'Forward 1m'
slug = 'Forward 1m'
description = '''\
-
+ Write a program that would make the robot drive forward and stop after 1 meter.
'''
hint = {
-
+ 'mW_init':mod.hint['init'],
+ 'connectMotorLeft':mod.hint['connectMotorLeft'],
+ 'connectMotorRight':mod.hint['connectMotorRight'],
+ 'moveSteering':mod.hint['moveSteering'],
+ 'onForRotations':mod.hint['onForRotations'],
+ 'direction':mod.hint['direction']+['''<p><code>robot.move_steering( '...', direction=0, ... )</code>.</p>'''],
+ 'seconds':mod.hint['seconds']+['''<p><code>robot.move_steering( 'on_for_seconds', direction=0, seconds=3 )</code>.</p>'''],
+ 'rotations':mod.hint['rotations'],
}
+
+plan = ['''\
+<p>Program izvedemo v naslednjih korakih:</p>
+<ol>
+ <li>create a mindstorms_widgets() object, which represents the robot in your code.</li>
+ <li>connect the driving motors.</li>
+ <li>measure the circumference of robot's wheels and compute the number of rotations per meter.</li>
+ <li>synchronize the motors and run them so that the robot would move forward for computed number of rotations.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/forward1m/sl.py b/robot/problems/introduction/forward1m/sl.py
index 8045d58..f6209eb 100644
--- a/robot/problems/introduction/forward1m/sl.py
+++ b/robot/problems/introduction/forward1m/sl.py
@@ -4,7 +4,7 @@ name = 'Naprej 1m'
slug = 'Naprej 1m'
description = '''\
-<p>Napiši program, da bo robot peljal naravnost naprej 3 sekunde in se nato ustavil.</p>'''
+<p>Napiši program, da bo robot peljal 1 meter naravnost in se nato ustavil.</p>'''
hint = {
'mW_init':['''<p>Robota v programu predstavimo z mindstorms_widgets(): <code>robot = mindstorms_widgets()</code>.</p>'''],
@@ -12,12 +12,22 @@ hint = {
'''<p><code>robot.connect_motor( 'left' )</code>.</p>'''],
'connectMotorRight':['''<p>Robotu priključi desni motor</p>''',
'''<p><code>robot.connect_motor( 'right' )</code>.</p>'''],
- 'moveSteering':['''<p>Sinhroniziraj motorja in ju zaženi za 3 sekunde.</p>''',
+ 'moveSteering':['''<p>Sinhroniziraj motorja in ju zaženi.</p>''',
'''<p>Za sinhronizirano vožnjo je najbolj primerna metoda <code>robot.move_steering( ... )</code>.</p>'''],
'onForRotations':['''<p>Prvi argument metode <code>robot.move_steering</code> naj pove, da bo delovanje motorjev določeno s številom obratov.</p>''',
'''<p><code>robot.move_steering('on_for_rotations', ... )</code>.</p>'''],
'direction':['''<p>Navedi smer premikanja motorjev, naravnost = 0.</p>''',
'''<p><code>robot.move_steering( 'on_for_rotations', direction=0, ... )</code>.</p>'''],
- 'rotations':['''<p>Določi število obratov; za koliko obratov naj se zavrtita motorja? Izmeri dolžino 1m, izpisuj obrate <code>print(robot.motor['left'].count_per_rot, robot.motor['right'].count_per_rot)</code> in tako določi ustrezno število obratov.</p>''',
+ 'rotations':['''<p>Določi število obratov; za koliko obratov naj se zavrtita motorja? Izmeri obseg kolesa in preračunaj, koliko obratov je potrebnih za 1m.</p>''',
'''<p><code>robot.move_steering( 'on_for_rotations', direction=0, rotations=5 )</code>.</p>'''],
}
+
+plan = ['''\
+<p>Program izvedemo v naslednjih korakih:</p>
+<ol>
+ <li>Naredimo objekt mindstorms_widgets(), s katerim predstavimo robota.</li>
+ <li>Nanj povežemo oba pogonska motorja.</li>
+ <li>Vklopimo oba motorja v sinhronem načinu tako, da robot vozi naravnost.</li>
+ <li>Glede na obseg koles izračunamo, koliko obratov mora narediti kolo na dolžini 1m; ustrezno nastavimo število obratov, po katerih se robot ustavi.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/gyro90/common.py b/robot/problems/introduction/gyro90/common.py
index 06b4f1d..1828001 100644
--- a/robot/problems/introduction/gyro90/common.py
+++ b/robot/problems/introduction/gyro90/common.py
@@ -10,9 +10,6 @@ number = 7
visible = True
solution = '''\
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
-
robot = mindstorms_widgets()
robot.connect_motor( 'left' )
robot.connect_motor( 'right' )
@@ -21,11 +18,11 @@ robot.connect_sensor( 'gyro' )
robot.gyro_set_mode( 'angle' )
robot.reset_gyro()
-power = 15
+power = 10
robot.move_tank( 'on', lr_power=[power,-power] )
while robot.gyro_sensor_measure() < 90:
pass
-robot.move_tank( 'off' )
+robot.move_tank( 'off', brake_at_end=True )
'''
hint_type = {
diff --git a/robot/problems/introduction/gyro90/sl.py b/robot/problems/introduction/gyro90/sl.py
index 0a82c6d..c0f9451 100644
--- a/robot/problems/introduction/gyro90/sl.py
+++ b/robot/problems/introduction/gyro90/sl.py
@@ -27,3 +27,14 @@ hint = {
'while':['''<p>Program naj teče dokler je kot zasuka manjši od 90 stopinj.</p>''',
'''<p><code>robot.gyro_sensor_measure() < 90:</code></p>'''],
}
+
+plan = ['''\
+<p>Program izvedemo v naslednjih korakih:</p>
+<ol>
+ <li>Naredimo objekt mindstorms_widgets(), s katerim predstavimo robota.</li>
+ <li>Nanj povežemo oba pogonska motorja.</li>
+ <li>Povežemo žiroskop in ga resetiramo.</li>
+ <li>Vklopimo oba motorja tako, da se vrtita z enako močjo, a v različnih smereh; robot se začne obračati na mestu.</li>
+ <li>V zanki merimo kot zasuka in zanko končamo, ko kot doseže 90 stopinj.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/gyrosquare/common.py b/robot/problems/introduction/gyrosquare/common.py
index 5bf6068..79ae131 100644
--- a/robot/problems/introduction/gyrosquare/common.py
+++ b/robot/problems/introduction/gyrosquare/common.py
@@ -10,8 +10,7 @@ number = 8
visible = True
solution = '''\
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
+import time
robot = mindstorms_widgets()
robot.connect_motor( 'left' )
@@ -19,20 +18,21 @@ robot.connect_motor( 'right' )
robot.connect_sensor( 'gyro' )
robot.gyro_set_mode( 'angle' )
-robot.reset_gyro()
-power = 20
-def forward_and_turnRight(power, angle):
- robot.move_steering( 'on_for_seconds', direction=0, power=power, seconds=2 )
+def forward_and_turnRight(power=10, angle=90):
+ robot.move_steering( 'on_for_seconds', direction=0, power=power, seconds=5 )
+ time.sleep(.5)
+ robot.reset_gyro()
+ robot.gyro_set_mode( 'angle' )
+ print(robot.gyro_sensor_measure( ))
robot.move_tank( 'on', lr_power=[power,-power] )
- while robot.gyro_sensor_measure( 'angle' ) < angle:
+ while robot.gyro_sensor_measure( ) < angle:
pass
- robot.move_tank( 'off' )
+ robot.move_tank( 'off', brake_at_end=True )
+ print(robot.gyro_sensor_measure( ))
-forward_and_turnRight(power, 89)
-forward_and_turnRight(power, 179)
-forward_and_turnRight(power, 269)
-forward_and_turnRight(power, 359)
+for i in range(4):
+ forward_and_turnRight()
'''
hint_type = {
diff --git a/robot/problems/introduction/gyrosquare/sl.py b/robot/problems/introduction/gyrosquare/sl.py
index 16b2c94..7d1f832 100644
--- a/robot/problems/introduction/gyrosquare/sl.py
+++ b/robot/problems/introduction/gyrosquare/sl.py
@@ -36,3 +36,14 @@ hint = {
'seconds':['''<p>Napiši časovno omejitev v sekundah.</p>''',
'''<p><code>robot.move_steering( 'on_for_seconds', direction=0, seconds=3 )</code>.</p>'''],
}
+
+plan = ['''\
+<p>Program izvedemo v naslednjih korakih:</p>
+<ol>
+ <li>Naredimo objekt mindstorms_widgets(), s katerim predstavimo robota.</li>
+ <li>Nanj povežemo oba pogonska motorja.</li>
+ <li>Povežemo žiroskop in ga resetiramo.</li>
+ <li>Napišemo funkcijo, ki robota pelje naravnost po stranici, nato pa ga na mestu obrne za 90 stopinj.</li>
+ <li>Zgornja funkcijo pokličemo 4-krat zaporedoma.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/mindstorms_widgets_OLD.py b/robot/problems/introduction/mindstorms_widgets_OLD.py
index 4151133..f69f5c7 100644
--- a/robot/problems/introduction/mindstorms_widgets_OLD.py
+++ b/robot/problems/introduction/mindstorms_widgets_OLD.py
@@ -302,6 +302,7 @@ class mindstorms_widgets:
if mode == 'on' and pulse:
self._led_pulse( color )
pass
+
# the sensor should be perfectly still while resetting the gyro
def resetGyro(self):
self.gs.mode = 'GYRO-RATE'
diff --git a/robot/problems/introduction/printcolors/common.py b/robot/problems/introduction/printcolors/common.py
index 4377c57..79f4d2a 100644
--- a/robot/problems/introduction/printcolors/common.py
+++ b/robot/problems/introduction/printcolors/common.py
@@ -11,8 +11,6 @@ visible = True
solution = '''\
import time
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
color_table = ['none', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown']
@@ -24,7 +22,7 @@ robot.connect_sensor( 'color' )
robot.move_steering( 'on')
start = time.time()
color = -1
-while time.time()-start < 2.1:
+while time.time()-start < 1.2:
c = robot.color_sensor_measure('color')
if c!=color:
print( c, color_table[c])
diff --git a/robot/problems/introduction/printcolors/naloga09_printColors.py b/robot/problems/introduction/printcolors/naloga09_printColors.py
index 59dfdb0..2e9d323 100644
--- a/robot/problems/introduction/printcolors/naloga09_printColors.py
+++ b/robot/problems/introduction/printcolors/naloga09_printColors.py
@@ -17,8 +17,7 @@ Naloga 9:
import sys
sys.path.append('/home/user/codeq')
import time
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
+from mindstorms_widgets import *
color_table = ['none', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown']
diff --git a/robot/problems/introduction/printcolors/sl.py b/robot/problems/introduction/printcolors/sl.py
index d233b0e..c705eaa 100644
--- a/robot/problems/introduction/printcolors/sl.py
+++ b/robot/problems/introduction/printcolors/sl.py
@@ -34,3 +34,16 @@ hint = {
'''<p><code>while time.time()-start < 1.1:</code>.</p>'''],
'print':['''<p>V zanki na zaslon izpisuj barvo, ki jo zazna robot.</p>''']
}
+
+plan = ['''\
+<p>Program izvedemo v naslednjih korakih:</p>
+<ol>
+ <li>Naredimo objekt mindstorms_widgets(), s katerim predstavimo robota.</li>
+ <li>Nanj povežemo oba pogonska motorja.</li>
+ <li>Povežemo barvni senzor.</li>
+ <li>Vklopimo oba motorja tako, da robot vozi naravnost.</li>
+ <li>V zanki naj robot bere barve in vsako izpiše na zaslon.</li>
+ <li>Zanka naj se konča po vnaprej določenem času, npr. 3 sekunde.</li>
+ <li>Ustavimo oba motorja.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/rotateback/common.py b/robot/problems/introduction/rotateback/common.py
index 10cca87..7c8ce44 100644
--- a/robot/problems/introduction/rotateback/common.py
+++ b/robot/problems/introduction/rotateback/common.py
@@ -10,9 +10,6 @@ number = 11
visible = True
solution = '''\
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
-
def sgn(x):
return -1 if x<0 else (1 if x>0 else 0)
diff --git a/robot/problems/introduction/rotateback/naloga11_rotateBack.py b/robot/problems/introduction/rotateback/naloga11_rotateBack.py
index 0bab735..2677f05 100644
--- a/robot/problems/introduction/rotateback/naloga11_rotateBack.py
+++ b/robot/problems/introduction/rotateback/naloga11_rotateBack.py
@@ -2,12 +2,11 @@
# coding=utf-8
print ("""
-Naloga 11:
+Naloga 11: Robot naj drži smer - če ga obrnemo iz začetne smeri, naj se zasuka nazaj v prvotno smer. Ob pritisku na stikalo, naj se resetira (smer nastavi na 0).
""")
import sys
sys.path.append('/home/user/codeq')
import time
-from ev3dev import *
from mindstorms_widgets import mindstorms_widgets
def sgn(x):
diff --git a/robot/problems/introduction/rotateback/sl.py b/robot/problems/introduction/rotateback/sl.py
index 269ea34..3242a80 100644
--- a/robot/problems/introduction/rotateback/sl.py
+++ b/robot/problems/introduction/rotateback/sl.py
@@ -31,3 +31,15 @@ hint = {
'while':['''<p>Program naj teče v neskončni zanki.</p>''',
'''<p><code>while 1:</code></p>'''],
}
+
+plan = ['''\
+<p>Program izvedemo v naslednjih korakih:</p>
+<ol>
+ <li>Naredimo objekt mindstorms_widgets(), s katerim predstavimo robota.</li>
+ <li>Nanj povežemo oba pogonska motorja.</li>
+ <li>Robotu dodamo žiroskop in ga resetiramo.</li>
+ <li>Robotu dodamo stikalo.</li>
+ <li>V neskončni zanki beremo vrednost kota z žiroskopom.</li>
+ <li>Glede na zasuk iz začetne lege, robota na mestu obrnemo v začetno smer.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/sl.py b/robot/problems/introduction/sl.py
new file mode 100644
index 0000000..24a72ca
--- /dev/null
+++ b/robot/problems/introduction/sl.py
@@ -0,0 +1,2 @@
+name = 'Uvod'
+description = 'Premikanje in zaznavanje.'
diff --git a/robot/problems/introduction/spotturn90/common.py b/robot/problems/introduction/spotturn90/common.py
index add6643..e01de39 100644
--- a/robot/problems/introduction/spotturn90/common.py
+++ b/robot/problems/introduction/spotturn90/common.py
@@ -10,9 +10,6 @@ number = 3
visible = True
solution = '''\
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
-
robot = mindstorms_widgets()
robot.connect_motor( 'left' )
robot.connect_motor( 'right' )
@@ -30,7 +27,7 @@ hint_type = {
'seconds': Hint('seconds'),
}
-def hint( code):
+def hint( code ):
tokens = get_tokens(code)
# if code does not include mindstorms_widgets(), a student gets a hint that the robot should be somehow represented in the program
diff --git a/robot/problems/introduction/spotturn90/sl.py b/robot/problems/introduction/spotturn90/sl.py
index fe477aa..e3541c0 100644
--- a/robot/problems/introduction/spotturn90/sl.py
+++ b/robot/problems/introduction/spotturn90/sl.py
@@ -19,3 +19,14 @@ hint = {
'seconds':['''<p>Napiši časovno omejitev v sekundah.</p>''',
'''<p><code>robot.move_tank( 'on_for_seconds', ..., seconds=... )</code>.</p>'''],
}
+
+plan = ['''\
+<p>Program izvedemo v naslednjih korakih:</p>
+<ol>
+ <li>Naredimo objekt mindstorms_widgets(), s katerim predstavimo robota.</li>
+ <li>Nanj povežemo oba pogonska motorja.</li>
+ <li>Povežemo barvni senzor.</li>
+ <li>Vklopimo oba motorja tako, da se z enako močjo vrtita v različnih smereh.</li>
+ <li>Motorja izlopimo po pretečenem času, ki pri izbrani moči obrne robota za 90 stopinj.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/square20/common.py b/robot/problems/introduction/square20/common.py
index a293712..ce8bc14 100644
--- a/robot/problems/introduction/square20/common.py
+++ b/robot/problems/introduction/square20/common.py
@@ -10,9 +10,6 @@ number = 4
visible = True
solution = '''\
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
-
robot = mindstorms_widgets()
robot.connect_motor( 'left' )
robot.connect_motor( 'right' )
diff --git a/robot/problems/introduction/square20/sl.py b/robot/problems/introduction/square20/sl.py
index f52ddf7..50b335f 100644
--- a/robot/problems/introduction/square20/sl.py
+++ b/robot/problems/introduction/square20/sl.py
@@ -27,3 +27,14 @@ hint = {
'lrPower': ['''<p>Za obrat na mestu se morata kolesi vrteti z enako močjo in v nasprotni smeri.</p>''',
'''<p><code>robot.move_tank( 'on_for_seconds', lr_power=[20,-20], seconds=.95 )</code>.</p>'''],
}
+
+plan = ['''\
+<p>Program izvedemo v naslednjih korakih:</p>
+<ol>
+ <li>Naredimo objekt mindstorms_widgets(), s katerim predstavimo robota.</li>
+ <li>Nanj povežemo oba pogonska motorja.</li>
+ <li>Vklopimo oba motorja tako, da robot vozi naravnost.</li>
+ <li>Robot se na mestu obrne za 90 stopinj; motorja z enako močjo, v različnih smereh.</li>
+ <li>Še 3-krat ponovimo koraka 3 in 4.</li>
+</ol>'''
+]
diff --git a/robot/problems/introduction/wall1m/common.py b/robot/problems/introduction/wall1m/common.py
index 07d1e1a..e8a5917 100644
--- a/robot/problems/introduction/wall1m/common.py
+++ b/robot/problems/introduction/wall1m/common.py
@@ -10,18 +10,15 @@ number = 6
visible = True
solution = '''\
-from ev3dev import *
-from mindstorms_widgets import mindstorms_widgets
-
robot = mindstorms_widgets()
robot.connect_motor( 'left' )
robot.connect_motor( 'right' )
robot.connect_sensor( 'ultrasonic' )
robot.move_steering( 'on', power=80 )
-while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 500:
+while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 50:
pass
robot.move_steering( 'on', power=20 )
-while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 200:
+while robot.ultrasonic_sensor_measure( 'distance-cm' ) > 20:
pass
robot.move_steering( 'off' )
'''
diff --git a/robot/problems/introduction/wall1m/sl.py b/robot/problems/introduction/wall1m/sl.py
index 18518d5..cbb27ed 100644
--- a/robot/problems/introduction/wall1m/sl.py
+++ b/robot/problems/introduction/wall1m/sl.py
@@ -29,3 +29,17 @@ hint = {
'while':['''<p>Uporabi zanko: robot naj se pelje naprej, dokler ne pride do razdalje 50 cm od zida.</p>''',
'''<p>Uporabi še eno zanko: robot naj se pelje naprej z 20% močjo, dokler ne pride do razdalje 20 cm od zida.</p>'''],
}
+
+plan = ['''\
+<p>Program izvedemo v naslednjih korakih:</p>
+<ol>
+ <li>Naredimo objekt mindstorms_widgets(), s katerim predstavimo robota.</li>
+ <li>Nanj povežemo oba pogonska motorja.</li>
+ <li>Robotu dodamo ultrazvočni senzor.</li>
+ <li>Vklopimo oba motorja tako, da robot vozi naravnost; moč nastavimo na 80.</li>
+ <li>V zanki merimo razdaljo z UZ senzorjem; zanko končamo, ko je razdalja <50 cm.</li>
+ <li>Moč motorjev nastavimo na 20.</li>
+ <li>V zanki merimo razdaljo z UZ senzorjem; zanko končamo, ko je razdalja <20 cm.</li>
+ <li>Ustavimo oba motorja.</li>
+</ol>'''
+]
diff --git a/robot/sl.py b/robot/sl.py
index 9ffcc40..daf0496 100644
--- a/robot/sl.py
+++ b/robot/sl.py
@@ -5,7 +5,7 @@ description = 'Uvodni tečaj za robota.'
hint = {
'no_hint': ['''\
-<p>Namig ne obstaja! Poskusi uporabiti misli.</p>
+<p>Namig ne obstaja!</p>
'''],
'system_error': ['''\