diff options
Diffstat (limited to 'prolog/problems/family_relations')
-rw-r--r-- | prolog/problems/family_relations/aunt_2/en.py | 79 | ||||
-rw-r--r-- | prolog/problems/family_relations/brother_2/en.py | 71 | ||||
-rw-r--r-- | prolog/problems/family_relations/cousin_2/en.py | 73 | ||||
-rw-r--r-- | prolog/problems/family_relations/father_2/en.py | 55 | ||||
-rw-r--r-- | prolog/problems/family_relations/grandparent_2/en.py | 62 | ||||
-rw-r--r-- | prolog/problems/family_relations/mother_2/en.py | 56 | ||||
-rw-r--r-- | prolog/problems/family_relations/sister_2/en.py | 75 |
7 files changed, 451 insertions, 20 deletions
diff --git a/prolog/problems/family_relations/aunt_2/en.py b/prolog/problems/family_relations/aunt_2/en.py index 4314a7a..f8bf35b 100644 --- a/prolog/problems/family_relations/aunt_2/en.py +++ b/prolog/problems/family_relations/aunt_2/en.py @@ -7,6 +7,81 @@ description = '''\ ?- aunt(sally, X). X = vanessa ; 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>Perhaps you can make use of the solution to one of the previous exercises?</p> +<p><img src="[%@resource Prolog_aunt_06.svg%]" alt="My sibling has a child..." /></p> +''', '''\ +<p>If <code>X</code> is a sister of the parent of <code>Y</code>, +then <code>X</code> is the aunt of <code>Y</code>.</p> +''', '''\ +<p><img src="[%@resource Prolog_aunt_07.svg%]" alt="A sister of Y's parent is the aunt of Y." /></p> +'''] + +hint = { + 'x_and_y_mixed_up': '''\ +<p><code>X</code> should be the aunt of <code>Y</code>, not the other way around.</p> +''', + + 'precedence_fail': '''\ +<p>Did you mix up the precedence of operators <em>or</em> & <em>and</em>?</p> +<p>Operator <em>and</em> has higher precedence than operator <em>or</em>. +If you wish to change that you can use brackets (as usual in mathematics).</p> +''', + + 'x_must_have_sibling': '''\ +<p>An aunt usually has a sibling...</p> +<p><img src="[%@resource Prolog_aunt_02.svg%]" /></p> +''', + + 'x_must_be_female': '''\ +<p>An aunt is usually female.</p> +<p><img src="[%@resource Prolog_aunt_05.svg%]" /></p> +''', # TODO: Loni should mark female gender on some aunt hints! + + 'y_must_have_parent': '''\ +<p>It would probably make sense if the nephew has a parent, right?</p> +<p><img src="[%@resource Prolog_aunt_01.svg%]" /></p> +''', + + 'aunt_vs_mother': '''\ +<p>How can an aunt also be the mother of <code>Y</code>? +Did you forget to specify that an aunt and the parent of <code>Y</code> cannot be the same person?</p> +<p><img src="[%@resource Prolog_aunt_04.svg%]" /></p> +''', + + 'x_need_not_be_parent': '''\ +<p><code>X</code> doesn't need to have children to be somebody's aunt...</p> +''', + + 'y_need_not_be_parent': '''\ +<p>A nephew <code>Y</code> doesn't need to have children...</p> +''', + + 'nephews_parent_can_be_male': '''\ +<p>A parent of nephew <code>Y</code> can also be male +(which means that this parent cannot be a sister of <code>X</code>).</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> +''', + + 'interesting_tidbit': '''\ +<p>Interesting tidbit. This exercise could also be solved using the solution to the <code>sister/2</code> +relation. An aunt is a sister of some parent of <code>Y</code>.</p> +<p><img src="[%@resource Prolog_aunt_07.svg%]" /></p> +''', # TODO: only trigger if sister is not part of correct solution +} -hint = {} 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/cousin_2/en.py b/prolog/problems/family_relations/cousin_2/en.py index 4ca9c87..a5627ee 100644 --- a/prolog/problems/family_relations/cousin_2/en.py +++ b/prolog/problems/family_relations/cousin_2/en.py @@ -2,11 +2,78 @@ name = 'cousin/2' slug = 'the cousin relation' description = '''\ -<p><code>cousin(X, Y)</code>: <code>X</code> is a cousin (male or female) of <code>Y</code>.</p> +<p><code>cousin(X, Y)</code>: <code>X</code> is a cousin of <code>Y</code>.</p> <pre> ?- cousin(andrew, X). X = vanessa ; 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>Perhaps you can make use of the solution to one of the previous exercises?</p> +<p><img src="[%@resource Prolog_cousin_01.svg%]" alt="I have a child, my sibling also has a child..." /></p> +<p>But of course it's also possible to solve without any of the previous solutions...</p> +''', '''\ +<p>If <code>PX</code> is a parent of <code>X</code> and +<code>PY</code> is a parent of <code>Y</code> and if +<code>PX</code> and <code>PY</code> are siblings, +then <code>X</code> is a cousin to <code>Y</code>.</p> +''', '''\ +<p><img src="[%@resource Prolog_cousin_03.svg%]" alt="I have a child, my sibling has a child, these two children +are therefore..." /></p> +'''] + +hint = { + 'gender_is_irrelevant': '''\ +<p>Is gender really important?</p> +''', + + 'gender_is_irrelevant_markup': '''\ +<p>Is this necessary?</p> +''', + + 'precedence_fail': '''\ +<p>Did you mix up the precedence of operators <em>or</em> & <em>and</em>?</p> +<p>Operator <em>and</em> has higher precedence than operator <em>or</em>. +If you wish to change that you can always use the brackets.</p> +''', + + 'cousin_vs_sibling': '''\ +<p>How can a cousin <code>X</code> at the same time also be a sibling of <code>Y</code>? +Did you perhaps forget that the parents of <code>X</code> and <code>Y</code> should not be the same? +(Be careful: if both a mother and a father are listed in the database, then prolog could find them as two +<em>different</em> parents, which is logically absolutely correct.)</p> +<p><img src="[%@resource Prolog_cousin_04.svg%]" /></p> +''', + + 'cousin_to_oneself': '''\ +<p>How can someone be a cousin to him- or herself? +Perhaps <code>X</code> and <code>Y</code> have the same parent?</p> +<p><img src="[%@resource Prolog_cousin_04.svg%]" /></p> +<p>Try this query: <code>?- cousin(X, X).</code></p> +''', + + 'cousin_need_not_be_parent': '''\ +<p>A cousin doesn't need to have children...</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> +''', + +# 'interesting_tidbit': '''\ +# <p>Zanimivost: nalogo bi lahko rešil tudi z uporabo rešitve za relacijo "sister". +# Teta je namreč sestra od starša od <code>Y</code>.</p> +# ''', +} -hint = {} diff --git a/prolog/problems/family_relations/father_2/en.py b/prolog/problems/family_relations/father_2/en.py index b37c666..f1a9040 100644 --- a/prolog/problems/family_relations/father_2/en.py +++ b/prolog/problems/family_relations/father_2/en.py @@ -9,6 +9,57 @@ description = '''\ ?- father(aleksander, X). X = luana ; X = daniela. -</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_father_01.svg%]" alt="A father is male and has a child." /></p>''', + '''\ +<p><img src="[%@resource Prolog_father_02.svg%]" alt="Father X is a parent of Y and is male." /></p>''', + '''\ +<p>If <code>X</code> is male and <code>X</code> is parent to <code>Y</code>, +then <code>X</code> is a father of <code>Y</code>.</p>''' +] + +hint = { + 'or_instead_of_and': '''\ +<p>Did you perhaps use a semicolon (that represents logical OR) instead of a comma (logical AND)?</p> +''', + + 'or_instead_of_and_two_rules': '''\ +<p>Did you perhaps write two rules: one for gender and one for parenthood? +Be careful: this is understood as one <em>or</em> the other, not as one <em>and</em> the other!</p> +''', + + 'x_must_be_male': '''\ +<p>A father is usually male.</p> +<p><img src="[%@resource Prolog_father_03.svg%]" /></p> +''', + + 'x_must_be_parent': '''\ +<p>A father is supposed to have at least one child... so he's a parent of somebody.</p> +<p><img src="[%@resource Prolog_father_04.svg%]" /></p> +''', + + 'y_can_be_of_any_gender': '''\ +<p><code>Y</code> can be of any gender.</p> +''', + + 'y_need_not_be_parent': '''\ +<p><code>Y</code> doesn't need to have children...</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/grandparent_2/en.py b/prolog/problems/family_relations/grandparent_2/en.py index 3aa9bfe..b8fca7c 100644 --- a/prolog/problems/family_relations/grandparent_2/en.py +++ b/prolog/problems/family_relations/grandparent_2/en.py @@ -9,6 +9,64 @@ description = '''\ X = patricia. ?- grandparent(tina, vanessa). true. -</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_grandparent_01.svg%]" alt="A grandparent has a child that has a child." /></p> +''', '''\ +<p>If <code>X</code> is a parent of a parent of <code>Y</code>, +then <code>X</code> is a grandparent of <code>Y</code>.</p> +''', '''\ +<p><img src="[%@resource Prolog_grandparent_02.svg%]" alt="A grandparent has a child that has a child of +his or her own." /></p> +'''] + +hint = { + 'no_common_z': '''\ +<p>Did you connect <code>X</code> and <code>Y</code> through some common person?</p> +''', + + 'gender_is_irrelevant': '''\ +<p>We're looking for a grandparent and a grandchild, the gender is not important.</p> +''', + + 'gender_is_irrelevant_markup': '''\ +<p>Is this necessary?</p> +''', + + 'or_instead_of_and': '''\ +<p>Did you perhaps use a semicolon (that represents logical OR) instead of a comma (logical AND)?</p> +''', + + 'x_must_be_parent': '''\ +<p>A grandparent surely has a child, right? So he or she is a parent of someone...</p> +<p><img src="[%@resource Prolog_grandparent_03.svg%]" </p> +''', + + 'x_need_not_have_parent': '''\ +<p>A parent of <code>X</code> is not really important if we're looking for a grandchild...</p> +''', + + 'y_must_have_parent': '''\ +<p>A grandchild <code>Y</code> must have a parent, right? And that parent is...</p> +<p><img src="[%@resource Prolog_grandparent_04.svg%]" </p> +''', + + 'y_need_not_be_parent': '''\ +<p>A grandchild <code>Y</code> doesn't really need to have children...</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/mother_2/en.py b/prolog/problems/family_relations/mother_2/en.py index f8cda9a..7d9de60 100644 --- a/prolog/problems/family_relations/mother_2/en.py +++ b/prolog/problems/family_relations/mother_2/en.py @@ -9,6 +9,58 @@ description = '''\ ?- mother(nevia, X). X = luana ; X = daniela. -</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_mother_01.svg%]" alt="A mother is female and has a child." /></p> +''', + '''\ +<p><img src="[%@resource Prolog_mother_02.svg%]" alt="Mother X is a parent of Y and is female." /></p>''', + '''\ +<p>If <code>X</code> is female and <code>X</code> is parent to <code>Y</code>, +then <code>X</code> is a mother of <code>Y</code>.</p>''' +] + +hint = { + 'or_instead_of_and': '''\ +<p>Did you perhaps use a semicolon (that represents logical OR) instead of a comma (logical AND)?</p> +''', + + 'or_instead_of_and_two_rules': '''\ +<p>Did you perhaps write two rules: one for gender and one for parenthood? +Be careful: this is understood as one <em>or</em> the other, not as one <em>and</em> the other!</p> +''', + + 'x_must_be_female': '''\ +<p>A mother is usually female.</p> +<p><img src="[%@resource Prolog_mother_03.svg%]" /></p> +''', + + 'x_must_be_parent': '''\ +<p>A mother is supposed to have at least one child... so she's a parent of somebody.</p> +<p><img src="[%@resource Prolog_mother_04.svg%]" /></p> +''', + + 'y_can_be_of_any_gender': '''\ +<p><code>Y</code> can be of any gender.</p> +''', + + 'y_need_not_be_parent': '''\ +<p><code>Y</code> doesn't need to have children...</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> ''', } |