summaryrefslogtreecommitdiff
path: root/prolog/problems/license_plates/checklicenseplate_3
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/problems/license_plates/checklicenseplate_3')
-rw-r--r--prolog/problems/license_plates/checklicenseplate_3/common.py41
-rw-r--r--prolog/problems/license_plates/checklicenseplate_3/sl.py18
2 files changed, 59 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 = {}