summaryrefslogtreecommitdiff
path: root/prolog
diff options
context:
space:
mode:
Diffstat (limited to 'prolog')
-rw-r--r--prolog/problems/family_relations/brother_2/common.py8
-rw-r--r--prolog/problems/family_relations/grandparent_2/common.py18
-rw-r--r--prolog/problems/family_relations/sister_2/common.py8
3 files changed, 17 insertions, 17 deletions
diff --git a/prolog/problems/family_relations/brother_2/common.py b/prolog/problems/family_relations/brother_2/common.py
index 87f27a3..8046b32 100644
--- a/prolog/problems/family_relations/brother_2/common.py
+++ b/prolog/problems/family_relations/brother_2/common.py
@@ -65,6 +65,10 @@ def hint(code, aux_code):
try:
engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
+ # use of \= or =\= instead of \==
+ if prolog.util.Token('NEQU', '\=') in tokens or prolog.util.Token('NEQA', '=\=') in tokens:
+ return [{'id': 'neq+_instead_of_neq'}]
+
# target predicate seems to always be false
if not prolog.engine.ask_truth(engine_id, 'brother(_, _)'):
return [{'id': 'predicate_always_false'}]
@@ -83,10 +87,6 @@ def hint(code, aux_code):
prolog.engine.ask_one(engine_id, 'brother(_, Y), female(Y)') == 'false':
return [{'id': 'y_can_be_of_any_gender'}]
- # use of \= or =\= instead of \==
- if prolog.util.Token('NEQU', '\=') in tokens or prolog.util.Token('NEQA', '=\=') in tokens:
- return [{'id': 'neq+_instead_of_neq'}]
-
# X and Y must be different
if prolog.util.Token('NEQ', '\==') not in tokens and prolog.engine.ask_truth(engine_id,
'setof(X, (member(X, [william, alessandro, andrew]), brother(X, X)), L), length(L, 3)'):
diff --git a/prolog/problems/family_relations/grandparent_2/common.py b/prolog/problems/family_relations/grandparent_2/common.py
index 431071e..1cfdfe8 100644
--- a/prolog/problems/family_relations/grandparent_2/common.py
+++ b/prolog/problems/family_relations/grandparent_2/common.py
@@ -71,6 +71,15 @@ def hint(code, aux_code):
# TODO: generic hint for:
# TODO: parent(X, Z1), parent(Z2, Y), Z1 = Z2
+ # gender testing is redundant
+ # this is not necessarily wrong, but worth mentioning anyway
+ targets = [prolog.util.Token('NAME', 'male'), prolog.util.Token('NAME', 'female'),
+ prolog.util.Token('NAME', 'mother'), prolog.util.Token('NAME', 'father')]
+ marks = [(t.pos, t.pos + len(t.val)) for t in tokens if t in targets]
+ if marks:
+ return [{'id': 'gender_is_irrelevant_markup', 'start': m[0], 'end': m[1]} for m in marks] + \
+ [{'id': 'gender_is_irrelevant'}]
+
# target predicate seems to always be false
if not prolog.engine.ask_truth(engine_id, 'grandparent(_, _)'):
return [{'id': 'predicate_always_false'}]
@@ -82,15 +91,6 @@ def hint(code, aux_code):
'findall(_, grandparent(X, Y), L), length(L, 1024)'):
return [{'id': 'no_common_z'}]
- # gender testing is redundant
- # this is not necessarily wrong, but worth mentioning anyway
- targets = [prolog.util.Token('NAME', 'male'), prolog.util.Token('NAME', 'female'),
- prolog.util.Token('NAME', 'mother'), prolog.util.Token('NAME', 'father')]
- marks = [(t.pos, t.pos + len(t.val)) for t in tokens if t in targets]
- if marks:
- return [{'id': 'gender_is_irrelevant_markup', 'start': m[0], 'end': m[1]} for m in marks] + \
- [{'id': 'gender_is_irrelevant'}]
-
# OR (;) instead of AND (,)
# this hint has to be before the next two
# as otherwise those two would always override it
diff --git a/prolog/problems/family_relations/sister_2/common.py b/prolog/problems/family_relations/sister_2/common.py
index 2be3ab3..8493007 100644
--- a/prolog/problems/family_relations/sister_2/common.py
+++ b/prolog/problems/family_relations/sister_2/common.py
@@ -91,6 +91,10 @@ def hint(code, aux_code):
try:
engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
+ # use of \= or =\= instead of \==
+ if prolog.util.Token('NEQU', '\=') in tokens or prolog.util.Token('NEQA', '=\=') in tokens:
+ return [{'id': 'neq+_instead_of_neq'}]
+
# target predicate seems to always be false
if not prolog.engine.ask_truth(engine_id, 'sister(_, _)'):
return [{'id': 'predicate_always_false'}]
@@ -112,10 +116,6 @@ def hint(code, aux_code):
prolog.engine.ask_one(engine_id, 'sister(_, Y), male(Y)') == 'false':
return [{'id': 'y_can_be_of_any_gender'}]
- # use of \= or =\= instead of \==
- if prolog.util.Token('NEQU', '\=') in tokens or prolog.util.Token('NEQA', '=\=') in tokens:
- return [{'id': 'neq+_instead_of_neq'}]
-
# X and Y must be different
# this is the last code-specific hint (when everything else doesn't trigger anymore)
if prolog.util.Token('NEQ', '\==') not in tokens and prolog.engine.ask_truth(engine_id,