summaryrefslogtreecommitdiff
path: root/prolog/problems/lists_advanced/palindrome_1
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-20 17:13:12 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-20 17:13:12 +0100
commita37c3602e0deaa6da902b1202325b80624e21724 (patch)
treee6bc33171584629f9325b0549d475be80d6ddeee /prolog/problems/lists_advanced/palindrome_1
parent3cfb316886bafb00e1d12b7364892366497f0c16 (diff)
Prolog: add triggers for palindrome/min/max hints
Diffstat (limited to 'prolog/problems/lists_advanced/palindrome_1')
-rw-r--r--prolog/problems/lists_advanced/palindrome_1/common.py31
-rw-r--r--prolog/problems/lists_advanced/palindrome_1/sl.py20
2 files changed, 48 insertions, 3 deletions
diff --git a/prolog/problems/lists_advanced/palindrome_1/common.py b/prolog/problems/lists_advanced/palindrome_1/common.py
index 3d202b9..f1baf4e 100644
--- a/prolog/problems/lists_advanced/palindrome_1/common.py
+++ b/prolog/problems/lists_advanced/palindrome_1/common.py
@@ -28,6 +28,11 @@ hint_type = {
'predicate_always_false': Hint('predicate_always_false'),
'base_case': Hint('base_case'),
'timeout': Hint('timeout'),
+ '[X,X]_instead_of_[]_base_case': Hint('[X,X]_instead_of_[]_base_case'),
+ 'one_base_case_missing': Hint('one_base_case_missing'),
+ 'arbitrary_base_case': Hint('arbitrary_base_case'),
+ 'last_used': Hint('last_used'),
+ 'final_hint': Hint('final_hint'),
}
test_cases = [
@@ -56,6 +61,8 @@ 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):
@@ -72,14 +79,32 @@ 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'}]
- # missing/failed base case
- if not prolog.engine.ask_truthTO(engine_id, 'palindrome([])'):
- return [{'id': 'base_case'}]
+ if prolog.engine.ask_truthTO(engine_id,
+ 'palindrome([q, q]), \+ palindrome([]), \+ palindrome([q, a])'):
+ return [{'id': '[X,X]_instead_of_[]_base_case'}]
+
+ if prolog.engine.ask_truthTO(engine_id, '''\
+ palindrome([a, b, b, a]),
+ \+ palindrome([c, e, p, e, c])
+ ;
+ \+ palindrome([a, b, b, a]),
+ palindrome([c, e, p, e, c])'''):
+ return [{'id': 'one_base_case_missing'}]
+
+ if prolog.engine.ask_truthTO(engine_id, 'palindrome(kokos(1))'):
+ return [{'id': 'arbitrary_base_case'}]
+
+ 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, 'palindrome(_)'):
return [{'id': 'predicate_always_false'}]
+ # missing/failed base case
+ if not prolog.engine.ask_truthTO(engine_id, 'palindrome([])'):
+ return [{'id': 'base_case'}]
+
except socket.timeout as ex:
return [{'id': 'timeout'}]
diff --git a/prolog/problems/lists_advanced/palindrome_1/sl.py b/prolog/problems/lists_advanced/palindrome_1/sl.py
index 400ac6b..6f4a715 100644
--- a/prolog/problems/lists_advanced/palindrome_1/sl.py
+++ b/prolog/problems/lists_advanced/palindrome_1/sl.py
@@ -40,4 +40,24 @@ 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>
''',
+
+ '[X,X]_instead_of_[]_base_case': '''\
+<p>[X,X]_instead_of_[]_base_case')</p>
+''',
+
+ 'one_base_case_missing': '''\
+<p>one_base_case_missing</p>
+''',
+
+ 'arbitrary_base_case': '''\
+<p>arbitrary_base_case</p>
+''',
+
+ 'last_used': '''\
+<p>last_used</p>
+''',
+
+ 'final_hint': '''\
+<p>final_hint</p>
+''',
}