summaryrefslogtreecommitdiff
path: root/prolog/problems/family_relations/brother_2
diff options
context:
space:
mode:
authorMartin Možina <martin.mozina@fri.uni-lj.si>2015-10-18 19:21:36 +0200
committerMartin Možina <martin.mozina@fri.uni-lj.si>2015-10-18 19:21:36 +0200
commitce6b6b0bc9af3cff176bd995ee25c8334eea632c (patch)
tree0b6606017549c342171440fd61059e57195e7384 /prolog/problems/family_relations/brother_2
parent7dd2b4dc917fe26267c1db1f5f58585a5417cb8c (diff)
parent8f0a1bdd9a2f2e0b951dd07c23d7f4db1189aee5 (diff)
Merge branch 'master' of 192.168.15.97:codeq-problems
Diffstat (limited to 'prolog/problems/family_relations/brother_2')
-rw-r--r--prolog/problems/family_relations/brother_2/common.py12
-rw-r--r--prolog/problems/family_relations/brother_2/sl.py19
2 files changed, 24 insertions, 7 deletions
diff --git a/prolog/problems/family_relations/brother_2/common.py b/prolog/problems/family_relations/brother_2/common.py
index 48b89fe..654825e 100644
--- a/prolog/problems/family_relations/brother_2/common.py
+++ b/prolog/problems/family_relations/brother_2/common.py
@@ -23,8 +23,9 @@ brother(X, Y) :-
hint_type = {
'x_must_be_male': Hint('x_must_be_male'),
'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 = [
@@ -64,7 +65,7 @@ def test(program, solved_problems):
return passed, hints
def hint(program, solved_problems):
- # tokens = prolog.util.tokenize(program)
+ tokens = prolog.util.tokenize(program)
code = (program + '\n' +
server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
@@ -91,10 +92,15 @@ def hint(program, solved_problems):
return [{'id': 'y_can_be_of_any_gender'}]
# X and Y must be different
- 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, [william, alessandro, andrew]), brother(X, X)), L), length(L, 3)'):
return [{'id': 'x_y_must_be_different'}]
+ # X and Y must be different, but \== was used
+ if prolog.util.Token('NEQ', '\==') in tokens and prolog.engine.ask_truth(engine_id,
+ 'setof(X/Y, brother(X, Y), L), member(alessandro/alessandro, L), member(andrew/andrew, L), member(william/william, L)'):
+ return [{'id': 'neq_used_too_early'}]
+
except socket.timeout as ex:
pass
diff --git a/prolog/problems/family_relations/brother_2/sl.py b/prolog/problems/family_relations/brother_2/sl.py
index 96c6126..29703a1 100644
--- a/prolog/problems/family_relations/brother_2/sl.py
+++ b/prolog/problems/family_relations/brother_2/sl.py
@@ -22,14 +22,16 @@ potem je <code>X</code> brat od <code>Y</code>.</p>''',
]
hint = {
- 'x_y_must_be_different': '''\
+ 'x_y_must_be_different': [{'message': '''\
<p><img src="[%@resource Prolog_brother_04.svg%]" /></p>
<p>Si pomislil, da sta <code>X</code> in <code>Y</code> lahko ista oseba? Poskusi naslednjo poizvedbo:</p>
<pre>
?- brother(william, 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_male': '''\
<p><img src="[%@resource Prolog_brother_03.svg%]" /></p>
@@ -44,4 +46,13 @@ hint = {
<p><img src="[%@resource Prolog_brother_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>
+''',
+
}