summaryrefslogtreecommitdiff
path: root/prolog/problems/family_relations/ancestor_2/common.py
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-02 13:20:52 +0100
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-02 13:20:52 +0100
commite318ce671052e30dff8077d7ca72f8633cab9ffa (patch)
tree94ad6f401f15ce2b370185335f6ceeff88e79e2e /prolog/problems/family_relations/ancestor_2/common.py
parent5ade8edf713eea0fea65785de6cc61c591cf54fc (diff)
Improved hints for ancestor/2 and descendant/2.
Diffstat (limited to 'prolog/problems/family_relations/ancestor_2/common.py')
-rw-r--r--prolog/problems/family_relations/ancestor_2/common.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/prolog/problems/family_relations/ancestor_2/common.py b/prolog/problems/family_relations/ancestor_2/common.py
index 9346e5f..2353eab 100644
--- a/prolog/problems/family_relations/ancestor_2/common.py
+++ b/prolog/problems/family_relations/ancestor_2/common.py
@@ -84,6 +84,13 @@ def hint(code, aux_code):
return [{'id': 'grandparent_used_markup', 'start': m[0], 'end': m[1]} for m in marks] + \
[{'id': 'grandparent_used'}]
+ # descendant instead of ancestor (wrong direction)
+ # warning: knowledge base dependent
+ if prolog.engine.ask_truthTO(engine_id,
+ 'findall(_, ancestor(william, X), L1), length(L1, 2), \
+ findall(_, ancestor(X, william), L2), length(L2, 6)'):
+ return [{'id': 'wrong_direction'}]
+
# missing/failed base case
if prolog.engine.ask_truthTO(engine_id,
'findall(X/Y, parent(X, Y), L), member(X/Y, L), \+ ancestor(X, Y)'):
@@ -103,13 +110,6 @@ def hint(code, aux_code):
else:
return [{'id': 'ancestor_to_oneself'}]
- # descendant instead of ancestor (wrong direction)
- # warning: knowledge base dependent
- if prolog.engine.ask_truthTO(engine_id,
- 'findall(_, ancestor(william, X), L1), length(L1, 2), \
- findall(_, ancestor(X, william), L2), length(L2, 6)'):
- return [{'id': 'wrong_direction'}]
-
# Y does not necessarily need to be a parent
if prolog.engine.ask_one(engine_id,
'ancestor(_, Y), \+ parent(Y, _)') == 'false':