summaryrefslogtreecommitdiff
path: root/prolog
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-20 10:53:25 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-20 10:53:25 +0100
commitf193671b6ab09178e1dc1325f56844c22fa409b9 (patch)
treef333cd0e7c9fcb22c24151d916fc56a70502fe63 /prolog
parentd381d710ae10711f7717d82885dde6031f10a2d2 (diff)
Prolog: add triggers for shiftright hints
Diffstat (limited to 'prolog')
-rw-r--r--prolog/problems/lists_advanced/shiftright_2/common.py30
-rw-r--r--prolog/problems/lists_advanced/shiftright_2/sl.py15
2 files changed, 45 insertions, 0 deletions
diff --git a/prolog/problems/lists_advanced/shiftright_2/common.py b/prolog/problems/lists_advanced/shiftright_2/common.py
index 3df6621..b945440 100644
--- a/prolog/problems/lists_advanced/shiftright_2/common.py
+++ b/prolog/problems/lists_advanced/shiftright_2/common.py
@@ -23,6 +23,11 @@ hint_type = {
'eq_instead_of_equ': Hint('eq_instead_of_equ'),
'predicate_always_false': Hint('predicate_always_false'),
'timeout': Hint('timeout'),
+ 'conc_2nd_argument_not_1elem_list': Hint('conc_2nd_argument_not_1elem_list'),
+ 'arbitrary_result': Hint('arbitrary_result'),
+ 'shiftleftish_solution': Hint('shiftleftish_solution'),
+ 'last_used': Hint('last_used'),
+ 'final_hint': Hint('final_hint'),
}
test_cases = [
@@ -51,6 +56,9 @@ def test(code, aux_code):
prolog.engine.destroy(engine_id)
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ if n_correct == len(test_cases):
+ hints += [{'id': 'final_hint'}]
+
return n_correct, len(test_cases), hints
def hint(code, aux_code):
@@ -67,6 +75,28 @@ def hint(code, aux_code):
return [{'id': 'eq_instead_of_equ_markup', 'start': m[0], 'end': m[1]} for m in marks] + \
[{'id': 'eq_instead_of_equ'}]
+ # second argument to conc is not first element in list
+ if prolog.engine.ask_truthTO(engine_id,
+ 'findall(L, shiftright([a, b, c], L), [[[a, b, c]], [[b, c], a], [[c], a, b], [[], a, b, c]])'):
+ return [{'id': 'conc_2nd_argument_not_1elem_list'}]
+
+ # arbitrary result
+ if prolog.engine.ask_truthTO(engine_id, '''\
+ shiftright([a, b, c], [yowza, brix, cob])
+ ;
+ shiftright([a, b, yowza], [yowza | kokos(1)])
+ ;
+ findall(L, shiftright([a, b, c], L), [[[a, b, c] | b], [[b, c] | r], [[c] | i], [[] | x]])'''):
+ return [{'id': 'arbitrary_result'}]
+
+ # shiftleftish solution
+ if prolog.engine.ask_truthTO(engine_id, 'shiftright([a, b, c, yowza], [[b, c, yowza] | a])'):
+ return [{'id': 'shiftleftish_solution'}]
+
+ # last/2 used
+ if any(t.val == 'last' for t in tokens):
+ return [{'id': 'last_used'}]
+
# target predicate seems to always be false
if not prolog.engine.ask_truthTO(engine_id, 'shiftright(_, _)'):
return [{'id': 'predicate_always_false'}]
diff --git a/prolog/problems/lists_advanced/shiftright_2/sl.py b/prolog/problems/lists_advanced/shiftright_2/sl.py
index 33f2dc7..3dfb637 100644
--- a/prolog/problems/lists_advanced/shiftright_2/sl.py
+++ b/prolog/problems/lists_advanced/shiftright_2/sl.py
@@ -33,4 +33,19 @@ da je <code>X</code> hkrati starš in sestra od <code>Y</code> ali kaj podobno z
<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>
''',
+
+'conc_2nd_argument_not_1elem_list': '''\
+<p>conc_2nd_argument_not_1elem_list</p>''',
+
+'arbitrary_result': '''\
+<p>arbitrary_result</p>''',
+
+'shiftleftish_solution': '''\
+<p>shiftleftish_solution</p>''',
+
+'last_used': '''\
+<p>last_used</p>''',
+
+'final_hint': '''\
+<p>final_hint</p>''',
}