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/ancestor_2/common.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'prolog/problems/family_relations/ancestor_2/common.py') 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': -- cgit v1.2.1