diff options
Diffstat (limited to 'prolog/problems/family_relations/grandparent_2')
-rw-r--r-- | prolog/problems/family_relations/grandparent_2/common.py | 17 |
1 files changed, 11 insertions, 6 deletions
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 [] |