summaryrefslogtreecommitdiff
path: root/prolog/problems
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/problems')
-rw-r--r--prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/common.py26
-rw-r--r--prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/sl.py16
2 files changed, 41 insertions, 1 deletions
diff --git a/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/common.py b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/common.py
index 828b742..3b997dd 100644
--- a/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/common.py
+++ b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/common.py
@@ -25,6 +25,10 @@ hint_type = {
'eq_instead_of_equ': Hint('eq_instead_of_equ'),
'predicate_always_false': Hint('predicate_always_false'),
'base_case': Hint('base_case'),
+ 'extra_base_case': Hint('extra_base_case'),
+ 'arbitrary_base_case': Hint('arbitrary_base_case'),
+ 'arithmetics_used': Hint('arithmetics_used'),
+ 'odd_and_even_mixed_up': Hint('odd_and_even_mixed_up'),
'recursive_case': Hint('recursive_case'),
'timeout': Hint('timeout'),
}
@@ -76,9 +80,29 @@ def hint(code, aux_code):
[{'id': 'eq_instead_of_equ'}]
# missing/failed base case
- if not prolog.engine.ask_truthTO(engine_id, 'evenlen([]), oddlen([a])'):
+ if not prolog.engine.ask_truthTO(engine_id, 'evenlen([])'):
return [{'id': 'base_case'}]
+ # redundant base case when evenlen and oddlen call each other
+ if prolog.engine.ask_truthTO(engine_id,
+ 'findall(q, (oddlen([a, b, c, d, e]) ; evenlen([a, b, c, d, e, f])), [q, q, q, q])'):
+ return [{'id': 'extra_base_case'}]
+
+ # arbitrary base case
+ if prolog.engine.ask_truthTO(engine_id,
+ 'evenlen(qQ), evenlen(parent(X, q)) ; oddlen(qQ), oddlen(parent(X, q))'):
+ return [{'id': 'arbitrary_base_case'}]
+
+ # arithmetics used
+ if any(t.val in ('is', 'len', 'length') for t in tokens):
+ return [{'id': 'arithmetics_used'}]
+
+ # odd and even mixed up
+ # TODO base_case will typically fire first when this is true
+ if prolog.engine.ask_truthTO(engine_id,
+ 'oddlen([]), evenlen([q]), ! ; oddlen([q, q]), evenlen([q, q, q])'):
+ return [{'id': 'odd_and_even_mixed_up'}]
+
# target predicate seems to always be false
if not prolog.engine.ask_truthTO(engine_id, 'evenlen(_) ; oddlen(_)'):
return [{'id': 'predicate_always_false'}]
diff --git a/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/sl.py b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/sl.py
index d56cc10..8600c55 100644
--- a/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/sl.py
+++ b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/sl.py
@@ -31,6 +31,22 @@ implicitno že kar v argumentih predikata (glavi stavka).</p>
Do katerega elementa najlažje prideš?</p>
''',
+ 'extra_base_case': '''\
+<p>extra_base_case</p>
+''',
+
+ 'arbitrary_base_case': '''\
+<p>arbitrary_base_case</p>
+''',
+
+ 'arithmetics_used': '''\
+<p>arithmetics_used</p>
+''',
+
+'odd_and_even_mixed_up': '''\
+<p>odd_and_even_mixed_up</p>
+''',
+
'recursive_case': '''\
<p>Robni primer deluje. Kaj pa rekurzivni, splošni, primer?</p>
''',