diff options
author | Aleksander Sadikov <aleksander.sadikov@fri.uni-lj.si> | 2015-10-17 20:04:54 +0200 |
---|---|---|
committer | Aleksander Sadikov <aleksander.sadikov@fri.uni-lj.si> | 2015-10-17 20:04:54 +0200 |
commit | 86bfc55d2ddc19b79127f2c788609635b702dbfd (patch) | |
tree | d3349850f62e56c1cc13a29cae9790b59c42cfa6 /prolog/problems/family_relations/sister_2 | |
parent | 531bde7a2fe3d643e9b6ffe690405b6cc07c4964 (diff) |
Family relations section fully hint-ready (just a few minor things missing).
Diffstat (limited to 'prolog/problems/family_relations/sister_2')
-rw-r--r-- | prolog/problems/family_relations/sister_2/common.py | 12 | ||||
-rw-r--r-- | prolog/problems/family_relations/sister_2/sl.py | 19 |
2 files changed, 25 insertions, 6 deletions
diff --git a/prolog/problems/family_relations/sister_2/common.py b/prolog/problems/family_relations/sister_2/common.py index 627648c..c112a9c 100644 --- a/prolog/problems/family_relations/sister_2/common.py +++ b/prolog/problems/family_relations/sister_2/common.py @@ -23,8 +23,9 @@ sister(X, Y) :- hint_type = { 'x_must_be_female': Hint('x_must_be_female'), 'common_parent_needed': Hint('common_parent_needed'), - 'y_can_be_of_any_gender': Hint('Y_can_be_of_any_gender'), + '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'), } test_cases = [ @@ -121,10 +122,17 @@ def hint(program, solved_problems): # X and Y must be different # this is the last code-specific hint (when everything else doesn't trigger anymore) - if prolog.engine.ask_truth(engine_id, + if prolog.util.Token('NEQ', '\==') not in tokens and prolog.engine.ask_truth(engine_id, 'setof(X, (member(X, [sally, nevia, vanessa]), sister(X, X)), L), length(L, 3)'): return [{'id': 'x_y_must_be_different'}] + # X and Y must be different, but the user used '\==' + # most likely this means that \== was used before X and Y are known + # this is the last code-specific hint (when everything else doesn't trigger anymore) + if prolog.util.Token('NEQ', '\==') in tokens and prolog.engine.ask_truth(engine_id, + 'setof(X/Y, sister(X, Y), L), member(nevia/nevia, L), member(sally/sally, L), member(vanessa/vanessa, L)'): + return [{'id': 'neq_used_too_early'}] + # last hints are connected with programming style # here, this means detecting such code: # parent(P1, X), parent(P2, Y), P1 == P2 (or P1 = P2) diff --git a/prolog/problems/family_relations/sister_2/sl.py b/prolog/problems/family_relations/sister_2/sl.py index d69b56c..cb51592 100644 --- a/prolog/problems/family_relations/sister_2/sl.py +++ b/prolog/problems/family_relations/sister_2/sl.py @@ -21,14 +21,16 @@ potem je <code>X</code> sestra od <code>Y</code>.</p>''', ] hint = { - 'x_y_must_be_different': '''\ + 'x_y_must_be_different': [{'message': '''\ <p><img src="[%@resource Prolog_sister_04.svg%]" /></p> <p>Si pomislil, da sta <code>X</code> in <code>Y</code> lahko ista oseba? Poskusi naslednjo poizvedbo:</p> <pre> ?- sister(sally, Y). -</pre> -<p>VEČ... Kako naredim, da sta X in Y različna?</p> -''', +</pre>''', 'linkText': 'Kako lahko preverim, da sta <code>X</code> in <code>Y</code> različna?'}, +'''\ +<p>S pomočjo operatorja <code>\==</code> lahko preverim, da sta <code>X</code> in <code>Y</code> med seboj različna. +Na primer: <code>X \== Y</code></p> +'''], 'x_must_be_female': '''\ <p><img src="[%@resource Prolog_sister_03.svg%]" /></p> @@ -43,4 +45,13 @@ hint = { <p><img src="[%@resource Prolog_sister_05.svg%]" /></p> <p>Dobro bi bilo, da imata <code>X</code> in <code>Y</code> vsaj enega skupnega starša.</p> ''', + + 'neq_used_too_early': '''\ +<p>Si morda uporabil operator <code>\==</code> prezgodaj?</p> +<p>Poskusi ga pomakniti bolj proti koncu. Razlog za probleme je verjetno, +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.</p> +''', + } |