summaryrefslogtreecommitdiff
path: root/prolog/problems/license_plates
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/problems/license_plates')
-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
11 files changed, 267 insertions, 0 deletions
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 = {}