From df8c0b864281e448498cc244cac8fdcf985b373c Mon Sep 17 00:00:00 2001
From: Timotej Lazar
Date: Sat, 19 Mar 2016 10:05:37 +0100
Subject: Prolog: add triggers for evenlen+oddlen hints
---
.../lists_advanced/evenlen_1_+_oddlen_1/common.py | 26 +++++++++++++++++++++-
.../lists_advanced/evenlen_1_+_oddlen_1/sl.py | 16 +++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
(limited to 'prolog')
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
@@ -29,6 +29,22 @@ implicitno že kar v argumentih predikata (glavi stavka).
'base_case': '''\
Si pomislil na robni pogoj? Kaj je najbolj enostaven primer, ko je element v seznamu?
Do katerega elementa najlažje prideš?
+''',
+
+ 'extra_base_case': '''\
+extra_base_case
+''',
+
+ 'arbitrary_base_case': '''\
+arbitrary_base_case
+''',
+
+ 'arithmetics_used': '''\
+arithmetics_used
+''',
+
+'odd_and_even_mixed_up': '''\
+odd_and_even_mixed_up
''',
'recursive_case': '''\
--
cgit v1.2.1