summaryrefslogtreecommitdiff
path: root/prolog/problems
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-20 11:11:56 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-20 11:11:56 +0100
commit3cfb316886bafb00e1d12b7364892366497f0c16 (patch)
treebf78f8a61a84b9f728eed5bcedaf3168b61a801c /prolog/problems
parentf193671b6ab09178e1dc1325f56844c22fa409b9 (diff)
Prolog: add triggers for rev hints
Diffstat (limited to 'prolog/problems')
-rw-r--r--prolog/problems/lists_advanced/rev_2/common.py36
-rw-r--r--prolog/problems/lists_advanced/rev_2/sl.py28
2 files changed, 64 insertions, 0 deletions
diff --git a/prolog/problems/lists_advanced/rev_2/common.py b/prolog/problems/lists_advanced/rev_2/common.py
index d9becb6..ee8c9ac 100644
--- a/prolog/problems/lists_advanced/rev_2/common.py
+++ b/prolog/problems/lists_advanced/rev_2/common.py
@@ -27,6 +27,13 @@ hint_type = {
'base_case': Hint('base_case'),
'recursive_case': Hint('recursive_case'),
'timeout': Hint('timeout'),
+ 'invalid_insert_at_end': Hint('invalid_insert_at_end'),
+ 'base_case_at_len1': Hint('base_case_at_len1'),
+ 'arbitrary_base_case': Hint('arbitrary_base_case'),
+ 'forcing_result_onto_recursion': Hint('forcing_result_onto_recursion'),
+ 'using_other_solutions': Hint('using_other_solutions'),
+ 'insertion_at_beginning': Hint('insertion_at_beginning'),
+ 'conc_arg_not_list': Hint('conc_arg_not_list'),
}
test_cases = [
@@ -71,6 +78,35 @@ 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'}]
+ if prolog.engine.ask_truthTO(engine_id, 'rev([q], [q]), \+ rev([], [])'):
+ return [{'id': 'base_case_at_len1'}]
+
+ if prolog.engine.ask_truthTO(engine_id, 'rev([], kokos(1))'):
+ return [{'id': 'arbitrary_base_case'}]
+
+ if prolog.engine.ask_truthTO(engine_id, '''\
+ \+ rev([yowza, brix, cob], R),
+ asserta(rev([brix, cob], [[cob, brix] | yowza])),
+ rev([yowza, brix, cob], [cob, brix]),
+ retract(rev([brix, cob], [[cob, brix] | yowza]))'''):
+ return [{'id': 'forcing_result_onto_recursion'}]
+
+ if any(t.val in ('last', 'shiftleft', 'shiftright') for t in tokens):
+ return [{'id': 'using_other_solutions'}]
+
+ if prolog.engine.ask_truthTO(engine_id, 'rev([qa, qb, qc, qd], [qa, qb, qc, qd])'):
+ return [{'id': 'insertion_at_beginning'}]
+
+ if prolog.engine.ask_truthTO(engine_id, 'rev([a, b, c], [[[[] | c] | b] | a])'):
+ return [{'id': 'invalid_insert_at_end'}]
+
+ if prolog.engine.ask_truthTO(engine_id, '''\
+ \+ rev([yowza, brix, cob], R),
+ asserta(rev([brix, cob], [cob, brix])),
+ rev([yowza, brix, cob], [cob, brix | yowza]),
+ retract(rev([brix, cob], [cob, brix]))'''):
+ return [{'id': 'conc_arg_not_list'}]
+
# missing/failed base case
if not prolog.engine.ask_truthTO(engine_id, 'rev([], [])'):
return [{'id': 'base_case'}]
diff --git a/prolog/problems/lists_advanced/rev_2/sl.py b/prolog/problems/lists_advanced/rev_2/sl.py
index 666832d..806dc52 100644
--- a/prolog/problems/lists_advanced/rev_2/sl.py
+++ b/prolog/problems/lists_advanced/rev_2/sl.py
@@ -44,4 +44,32 @@ 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>
''',
+
+ 'base_case_at_len1': '''\
+<p>base_case_at_len1</p>
+''',
+
+ 'arbitrary_base_case': '''\
+<p>arbitrary_base_case</p>
+''',
+
+ 'forcing_result_onto_recursion': '''\
+<p>forcing_result_onto_recursion</p>
+''',
+
+ 'using_other_solutions': '''\
+<p>using_other_solutions</p>
+''',
+
+ 'insertion_at_beginning': '''\
+<p>insertion_at_beginning</p>
+''',
+
+ 'invalid_insert_at_end': '''\
+<p>invalid_insert_at_end</p>
+''',
+
+ 'conc_arg_not_list': '''\
+<p>conc_arg_not_list</p>
+''',
}