From e318ce671052e30dff8077d7ca72f8633cab9ffa Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Wed, 2 Mar 2016 13:20:52 +0100 Subject: Improved hints for ancestor/2 and descendant/2. --- prolog/problems/family_relations/descendant_2/common.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'prolog/problems/family_relations/descendant_2/common.py') diff --git a/prolog/problems/family_relations/descendant_2/common.py b/prolog/problems/family_relations/descendant_2/common.py index 70936da..b4d8f31 100644 --- a/prolog/problems/family_relations/descendant_2/common.py +++ b/prolog/problems/family_relations/descendant_2/common.py @@ -88,6 +88,13 @@ def hint(code, aux_code): return [{'id': 'grandparent_used_markup', 'start': m[0], 'end': m[1]} for m in marks] + \ [{'id': 'grandparent_used'}] + # ancestor instead of descendant (wrong direction) + # warning: knowledge base dependent + if prolog.engine.ask_truthTO(engine_id, + 'findall(_, descendant(william, X), L1), length(L1, 6), \ + findall(_, descendant(X, william), L2), length(L2, 2)'): + return [{'id': 'wrong_direction'}] + # missing/failed base case if prolog.engine.ask_truthTO(engine_id, 'parent(Y, X), \+ descendant(X, Y)'): @@ -100,13 +107,6 @@ def hint(code, aux_code): else: return [{'id': 'descendant_of_oneself'}] - # ancestor instead of descendant (wrong direction) - # warning: knowledge base dependent - if prolog.engine.ask_truthTO(engine_id, - 'findall(_, descendant(william, X), L1), length(L1, 6), \ - findall(_, descendant(X, william), L2), length(L2, 2)'): - return [{'id': 'wrong_direction'}] - # X does not necessarily need to be a parent if prolog.engine.ask_one(engine_id, 'descendant(X, _), \+ parent(X, _)') == 'false': -- cgit v1.2.1