summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-08-19 18:32:27 +0200
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-08-19 18:32:27 +0200
commit5684a512562eeb4de8ca02643335408b91bf9546 (patch)
treeae0909c34215d46311c438d4bad752742791b9a9
parent0a09672a992836c912be80a71b47eaf9bcce2d07 (diff)
English translation for sister/2 and brother/2 added.
-rw-r--r--prolog/problems/family_relations/brother_2/en.py71
-rw-r--r--prolog/problems/family_relations/sister_2/en.py75
2 files changed, 137 insertions, 9 deletions
diff --git a/prolog/problems/family_relations/brother_2/en.py b/prolog/problems/family_relations/brother_2/en.py
index 1295450..e0db1f5 100644
--- a/prolog/problems/family_relations/brother_2/en.py
+++ b/prolog/problems/family_relations/brother_2/en.py
@@ -2,11 +2,76 @@ name = 'brother/2'
slug = 'the brother relation'
description = '''\
-<p><code>brother(X, Y)</code>: <code>X</code> is a brother of <code>Y</code>.</p>
+<p><code>brother(X, Y)</code>: <code>X</code> is a (half)brother of <code>Y</code>.</p>
<pre>
?- brother(jeffrey, X).
X = william ;
X = sally.
-</pre>'''
+</pre>
+<p><a target="_blank" href="[%@resource famrel.svg%]">Family trees</a> are
+described with predicates <code>parent/2</code>, <code>male/1</code>, and
+<code>female/1</code>.</p>
+'''
-hint = {}
+plan = [
+ '''\
+<p><img src="[%@resource Prolog_brother_01.svg%]" alt="A brother is male and has a common parent with Y." /></p>''',
+ '''\
+<p>If <code>X</code> is male and if <code>X</code> and <code>Y</code> share a common parent
+then <code>X</code> is a brother of <code>Y</code>.</p>''',
+ '''\
+<p><img src="[%@resource Prolog_brother_02.svg%]" alt="Brother X is male and has
+at least one parent in common with Y." /></p>''',
+]
+
+hint = {
+ 'x_y_must_be_different': [{'message': '''\
+<p><img src="[%@resource Prolog_brother_04.svg%]" /></p>
+<p>What if <code>X</code> and <code>Y</code> are the same person? Try the following query:</p>
+<pre>
+?- brother(william, Y).
+</pre>''', 'linkText': 'How can I check that <code>X</code> and <code>Y</code> are different?'},
+'''\
+<p>Using the operator <code>\==</code> I can check that <code>X</code> and <code>Y</code> are different.
+For example: <code>X \== Y</code></p>
+'''],
+
+ 'x_must_be_male': '''\
+<p><img src="[%@resource Prolog_brother_03.svg%]" /></p>
+<p>A brother is usually male.</p>
+''',
+
+ 'y_can_be_of_any_gender': '''\
+<p><code>Y</code> can actually be of <em>any</em> gender.</p>
+''',
+
+ 'neq+_instead_of_neq': '''\
+<p>Use the operator \== instead of operators \= or =\=. It succeeds when the two operands are not the same,
+while \= succeeds if the operands <em>cannot be made</em> the same (cannot be unified), and =\= checks for
+arithmetic inequality and in this case both operands should be immediately arithmetically computable.</p>
+''',
+
+ 'common_parent_needed': '''\
+<p><img src="[%@resource Prolog_brother_05.svg%]" /></p>
+<p>It would make sense if <code>X</code> and <code>Y</code> have at least one parent in common.</p>
+''',
+
+ 'neq_used_too_early': '''\
+<p>Did you use the operator <code>\==</code> too early?</p>
+<p>Try moving it more towards the end of the rule. The problem is probably that the variables
+you are comparing don't yet have values assigned to them and are therefore different by default.
+Prolog doesn't check whether they become equal <em>later</em>, it only checks whether they're
+equal or not at the moment of comparison.</p>
+<p>Or maybe you're simply comparing the wrong two variables?</p>
+''',
+
+ 'predicate_always_false': '''\
+<p>It seems your predicate is <em>always</em> "false". Did you give it the correct name,
+or is it perhaps misspelled?</p>
+<p>If the name is correct, check whether something else is misspelled, perhaps there is a full stop instead of
+a comma or vice versa, or maybe you typed a variable name in lowercase?</p>
+<p>It is, of course, also possible that your conditions are too restrictive, or even impossible to satisfy
+(as would be, for example, the condition that <code>X</code> is both a parent and a sister of <code>Y</code>, or
+something similarly impossible).</p>
+''',
+}
diff --git a/prolog/problems/family_relations/sister_2/en.py b/prolog/problems/family_relations/sister_2/en.py
index 9b78c95..cbd975b 100644
--- a/prolog/problems/family_relations/sister_2/en.py
+++ b/prolog/problems/family_relations/sister_2/en.py
@@ -2,18 +2,81 @@ name = 'sister/2'
slug = 'the sister relation'
description = '''\
-<p><code>sister(X, Y)</code>: <code>X</code> is a sister of <code>Y</code>.</p>
+<p><code>sister(X, Y)</code>: <code>X</code> is a (half)sister of <code>Y</code>.</p>
<pre>
?- sister(vanessa, X).
X = patricia.
-</pre>'''
+</pre>
+<p><a target="_blank" href="[%@resource famrel.svg%]">Family trees</a> are
+described with predicates <code>parent/2</code>, <code>male/1</code>, and
+<code>female/1</code>.</p>
+'''
+
+plan = [
+ '''\
+<p><img src="[%@resource Prolog_sister_01.svg%]" alt="A sister is female and has a common parent with Y." /></p>''',
+ '''\
+<p>If <code>X</code> is female and if <code>X</code> and <code>Y</code> share a common parent
+then <code>X</code> is a sister of <code>Y</code>.</p>''',
+ '''\
+<p><img src="[%@resource Prolog_sister_02.svg%]" alt="Sister X is female and has
+at least one parent in common with Y." /></p>''',
+]
hint = {
- 'x_y_must_be_different': '''\
-<p>What if <code>X</code> and <code>Y</code> are the same person? Try the
-following query:</p>
+ 'x_y_must_be_different': [{'message': '''\
+<p><img src="[%@resource Prolog_sister_04.svg%]" /></p>
+<p>What if <code>X</code> and <code>Y</code> are the same person? Try the following query:</p>
<pre>
?- sister(sally, Y).
-</pre>
+</pre>''', 'linkText': 'How can I check that <code>X</code> and <code>Y</code> are different?'},
+'''\
+<p>Using the operator <code>\==</code> I can check that <code>X</code> and <code>Y</code> are different.
+For example: <code>X \== Y</code></p>
+'''],
+
+ 'x_must_be_female': '''\
+<p><img src="[%@resource Prolog_sister_03.svg%]" /></p>
+<p>A sister is usually female.</p>
+''',
+
+ 'y_can_be_of_any_gender': '''\
+<p><code>Y</code> can actually be of <em>any</em> gender.</p>
+''',
+
+ 'neq+_instead_of_neq': '''\
+<p>Use the operator \== instead of operators \= or =\=. It succeeds when the two operands are not the same,
+while \= succeeds if the operands <em>cannot be made</em> the same (cannot be unified), and =\= checks for
+arithmetic inequality and in this case both operands should be immediately arithmetically computable.</p>
+''',
+
+ 'common_parent_needed': '''\
+<p><img src="[%@resource Prolog_sister_05.svg%]" /></p>
+<p>It would make sense if <code>X</code> and <code>Y</code> have at least one parent in common.</p>
+''',
+
+ 'neq_used_too_early': '''\
+<p>Did you use the operator <code>\==</code> too early?</p>
+<p>Try moving it more towards the end of the rule. The problem is probably that the variables
+you are comparing don't yet have values assigned to them and are therefore different by default.
+Prolog doesn't check whether they become equal <em>later</em>, it only checks whether they're
+equal or not at the moment of comparison.</p>
+<p>Or maybe you're simply comparing the wrong two variables?</p>
+''',
+
+ 'predicate_always_false': '''\
+<p>It seems your predicate is <em>always</em> "false". Did you give it the correct name,
+or is it perhaps misspelled?</p>
+<p>If the name is correct, check whether something else is misspelled, perhaps there is a full stop instead of
+a comma or vice versa, or maybe you typed a variable name in lowercase?</p>
+<p>It is, of course, also possible that your conditions are too restrictive, or even impossible to satisfy
+(as would be, for example, the condition that <code>X</code> is both a parent and a sister of <code>Y</code>, or
+something similarly impossible).</p>
+''',
+
+ 'final_hint': '''\
+<p>In this exercise you used the \== operator. It succeeds if its two operands are not the same
+<em>at the moment</em> of comparison. If you put this goal at the start of your rule, it will
+not work as expected. (Go ahead, try and see what happens!)</p>
''',
}