From bc40d810afbcde332730d50ed490deb432689db1 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Sun, 28 Feb 2016 22:14:02 +0100 Subject: sister/2 and brother/2 hints improved. --- prolog/problems/family_relations/brother_2/common.py | 9 +++++++-- prolog/problems/family_relations/brother_2/sl.py | 6 ++++++ prolog/problems/family_relations/grandparent_2/common.py | 2 ++ prolog/problems/family_relations/sister_2/common.py | 9 +++++++-- prolog/problems/family_relations/sister_2/sl.py | 8 +++++++- 5 files changed, 29 insertions(+), 5 deletions(-) (limited to 'prolog/problems/family_relations') diff --git a/prolog/problems/family_relations/brother_2/common.py b/prolog/problems/family_relations/brother_2/common.py index c49489e..7f61744 100644 --- a/prolog/problems/family_relations/brother_2/common.py +++ b/prolog/problems/family_relations/brother_2/common.py @@ -26,6 +26,7 @@ hint_type = { 'y_can_be_of_any_gender': Hint('y_can_be_of_any_gender'), 'x_y_must_be_different': Hint('x_y_must_be_different'), 'neq_used_too_early': Hint('neq_used_too_early'), + 'nm_instead_of_neq': Hint('nm_instead_of_neq'), } test_cases = [ @@ -73,10 +74,14 @@ def hint(code, aux_code): return [{'id': 'common_parent_needed'}] # Y can be of any gender, incl. female - if prolog.engine.ask_one(engine_id, - 'brother(_, Y), female(Y)') == 'false': + if prolog.engine.ask_truth(engine_id, 'brother(_, Y)') and \ + prolog.engine.ask_one(engine_id, 'brother(_, Y), female(Y)') == 'false': return [{'id': 'y_can_be_of_any_gender'}] + # use of \= instead of \== + if prolog.util.Token('NEQ', '\=') in tokens: + return [{'id': 'nm_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/brother_2/sl.py b/prolog/problems/family_relations/brother_2/sl.py index 2d170aa..f8eba49 100644 --- a/prolog/problems/family_relations/brother_2/sl.py +++ b/prolog/problems/family_relations/brother_2/sl.py @@ -44,6 +44,11 @@ Na primer: X \== Y

'y_can_be_of_any_gender': '''\

Y je pravzaprav lahko poljubnega spola.

+''', + + 'nm_instead_of_neq': '''\ +

Uporabi raje operator \== namesto operatorja \=. Prvi preveri, da dva objekta nista enaka, +drugi pa ju poskusi unificirati (narediti enaka).

''', 'common_parent_needed': '''\ @@ -57,6 +62,7 @@ Na primer: X \== Y

da spremenljivki, ki ju primerjaš, še nimata določene vrednosti in sta zato različni. Prolog ne preverja, če kasneje morda postaneta enaki, ampak samo kakšni sta v trenutku, ko naleti na primerjavo.

+

Morda pa preprosto preverjaš napačni spremenljivki?

''', } diff --git a/prolog/problems/family_relations/grandparent_2/common.py b/prolog/problems/family_relations/grandparent_2/common.py index 618ad28..45273c6 100644 --- a/prolog/problems/family_relations/grandparent_2/common.py +++ b/prolog/problems/family_relations/grandparent_2/common.py @@ -133,3 +133,5 @@ def hint(code, aux_code): # things to discuss with Tim # * can we make predicate_always_false a ghint? # with this in mind: how can we supply/know the correct target name and arity? +# * popraviti je potrebno spremni tekst glede na novo lokacijo gumba Namig +# * what's the name of \= token? And what of =\= token? diff --git a/prolog/problems/family_relations/sister_2/common.py b/prolog/problems/family_relations/sister_2/common.py index 08f44b3..1bc9365 100644 --- a/prolog/problems/family_relations/sister_2/common.py +++ b/prolog/problems/family_relations/sister_2/common.py @@ -26,6 +26,7 @@ hint_type = { 'y_can_be_of_any_gender': Hint('y_can_be_of_any_gender'), 'x_y_must_be_different': Hint('x_y_must_be_different'), 'neq_used_too_early': Hint('neq_used_too_early'), + 'nm_instead_of_neq': Hint('nm_instead_of_neq'), } test_cases = [ @@ -102,10 +103,14 @@ def hint(code, aux_code): # as this is after previous hints, by this stage the code probably # does return some sensible results already # this is an example of using the ordering of hints for easier trigger checks - if prolog.engine.ask_one(engine_id, - 'sister(_, Y), male(Y)') == 'false': + if prolog.engine.ask_truth(engine_id, 'sister(_, Y)') and \ + prolog.engine.ask_one(engine_id, 'sister(_, Y), male(Y)') == 'false': return [{'id': 'y_can_be_of_any_gender'}] + # use of \= instead of \== + if prolog.util.Token('NEQ', '\=') in tokens: + return [{'id': 'nm_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, diff --git a/prolog/problems/family_relations/sister_2/sl.py b/prolog/problems/family_relations/sister_2/sl.py index 6c36bce..5fa9d1c 100644 --- a/prolog/problems/family_relations/sister_2/sl.py +++ b/prolog/problems/family_relations/sister_2/sl.py @@ -4,7 +4,7 @@ name = 'sister/2' slug = 'X je sestra od Y' description = '''\ -

sister(?X, ?Y): X je sestra od Y. Primer:

+

sister(?X, ?Y): X je (pol)sestra od Y. Primer:

 ?- sister(vanessa, Y).
   Y = patricia.
@@ -43,6 +43,11 @@ Na primer: X \== Y

'y_can_be_of_any_gender': '''\

Y je pravzaprav lahko poljubnega spola.

+''', + + 'nm_instead_of_neq': '''\ +

Uporabi raje operator \== namesto operatorja \=. Prvi preveri, da dva objekta nista enaka, +drugi pa ju poskusi unificirati (narediti enaka).

''', 'common_parent_needed': '''\ @@ -56,6 +61,7 @@ Na primer: X \== Y

da spremenljivki, ki ju primerjaš, še nimata določene vrednosti in sta zato različni. Prolog ne preverja, če kasneje morda postaneta enaki, ampak samo kakšni sta v trenutku, ko naleti na primerjavo.

+

Morda pa preprosto preverjaš napačni spremenljivki?

''', } -- cgit v1.2.1