diff options
author | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2016-03-11 14:56:55 +0100 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2016-03-11 14:56:55 +0100 |
commit | 3146be47a651c357f2a221c39f558d43255cc25c (patch) | |
tree | 6c1f8be00e831a152ae3433ec36ce4aaeec308be | |
parent | 78ab6295925db9b64cbd5b3cd7a0d278510f8857 (diff) |
Prolog: add problem lists/last_elem_2
-rw-r--r-- | prolog/problems/lists/last_elem_2/common.py | 46 | ||||
-rw-r--r-- | prolog/problems/lists/last_elem_2/en.py | 13 | ||||
-rw-r--r-- | prolog/problems/lists/last_elem_2/sl.py | 21 |
3 files changed, 80 insertions, 0 deletions
diff --git a/prolog/problems/lists/last_elem_2/common.py b/prolog/problems/lists/last_elem_2/common.py new file mode 100644 index 0000000..b18243d --- /dev/null +++ b/prolog/problems/lists/last_elem_2/common.py @@ -0,0 +1,46 @@ +from operator import itemgetter +import prolog.engine +import prolog.util +import socket +from server.hints import Hint, HintPopup +import server.problems + +id = 10000 +number = 2 +visible = True +facts = None + +solution = '''\ +''' + +hint_type = { +} + +test_cases = [ + ('last_elem([X], c)', + [{'X': 'c'}]), + ('last_elem([y, l, r, g, a], X)', + [{'X': 'a'}]), +] + +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 + except socket.timeout: + pass + finally: + if engine_id: + prolog.engine.destroy(engine_id) + + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + return n_correct, len(test_cases), hints + +def hint(code, aux_code): + return [] diff --git a/prolog/problems/lists/last_elem_2/en.py b/prolog/problems/lists/last_elem_2/en.py new file mode 100644 index 0000000..93c7c05 --- /dev/null +++ b/prolog/problems/lists/last_elem_2/en.py @@ -0,0 +1,13 @@ +name = 'last_elem/2' +slug = 'find last element in list' + +description = '''\ +<p><code>last_elem(L, E)</code>: <code>E</code> is the last element of list <code>L</code>.</p> +<pre> +?- last_elem([1,2,3], X). + X = 3. +?- last_elem([3,2,X], 1). + X = 1. +</pre>''' + +hint = {} diff --git a/prolog/problems/lists/last_elem_2/sl.py b/prolog/problems/lists/last_elem_2/sl.py new file mode 100644 index 0000000..c77ef57 --- /dev/null +++ b/prolog/problems/lists/last_elem_2/sl.py @@ -0,0 +1,21 @@ +name = 'last_elem/2' +slug = 'Vrni zadnji element seznama' + +description = '''\ +<p><code>last_elem(L, E)</code>: <code>E</code> je zadnji element seznama <code>L</code>.</p> +<pre> +?- last_elem([1,2,3], X). + X = 3. +?- last_elem([3,2,X], 1). + X = 1. +</pre> +''' + +plan = [] + +hint = { + 'timeout': '''\ +<p>Je morda na delu potencialno neskončna rekurzija? Kako se bo ustavila?</p> +<p>Morda pa je kriv tudi manjkajoč, neustrezen ali preprosto nekompatibilen (s splošnim primerom) robni pogoj?</p> +''', +} |