From aec4e861a2477762326c0f9b001668f5c1ff9ddb Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Wed, 30 Sep 2015 17:39:14 +0200 Subject: Figures added for mother problem. --- .../problems/family_relations/grandparent_2/common.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'prolog/problems/family_relations/grandparent_2') diff --git a/prolog/problems/family_relations/grandparent_2/common.py b/prolog/problems/family_relations/grandparent_2/common.py index 98e40fc..8ccd23d 100644 --- a/prolog/problems/family_relations/grandparent_2/common.py +++ b/prolog/problems/family_relations/grandparent_2/common.py @@ -103,16 +103,21 @@ def hint(program, solved_problems): 'grandparent(X, _), \+ parent(X, _)'): return [{'id': 'x_must_be_parent'}] - # X does not necessarily need to have a parent - if prolog.engine.ask_one(engine_id, - 'grandparent(X, _), \+ parent(_, X)') == 'false': - return [{'id': 'x_need_not_have_parent'}] - # Y must have a parent if prolog.engine.ask_truth(engine_id, 'grandparent(_, Y), \+ parent(_, Y)'): return [{'id': 'y_must_have_parent'}] + # stop further hint testing if target predicate is always true or always false + if prolog.engine.ask_truth(engine_id, + '\+ grandparent(_, _) ; findall(X/Y, grandparent(X, Y), [A/B]), var(A), var(B)'): + return [] + + # X does not necessarily need to have a parent + if prolog.engine.ask_one(engine_id, + 'grandparent(X, _), \+ parent(_, X)') == 'false': + return [{'id': 'x_need_not_have_parent'}] + # Y does not necessarily need to be a parent if prolog.engine.ask_one(engine_id, 'grandparent(_, Y), \+ parent(Y, _)') == 'false': @@ -125,5 +130,5 @@ def hint(program, solved_problems): if engine_id: prolog.engine.destroy(engine_id) - return None + return [] -- cgit v1.2.1