diff options
author | Aleksander Sadikov <aleksander.sadikov@fri.uni-lj.si> | 2016-09-08 00:28:56 +0200 |
---|---|---|
committer | Aleksander Sadikov <aleksander.sadikov@fri.uni-lj.si> | 2016-09-08 00:28:56 +0200 |
commit | 4a01e895b521c75406270abd581cd3fbb09f2c08 (patch) | |
tree | 70d1f13100f3ae8bf112165cd88dfcd396e9cb9a /prolog/problems/lists_advanced | |
parent | d259285459176fc281193adb12483a6e6d527cf5 (diff) |
English translations for min/2 and max/2 added.
Diffstat (limited to 'prolog/problems/lists_advanced')
-rw-r--r-- | prolog/problems/lists_advanced/max_2/en.py | 87 | ||||
-rw-r--r-- | prolog/problems/lists_advanced/max_2/sl.py | 5 | ||||
-rw-r--r-- | prolog/problems/lists_advanced/min_2/en.py | 89 | ||||
-rw-r--r-- | prolog/problems/lists_advanced/min_2/sl.py | 7 |
4 files changed, 178 insertions, 10 deletions
diff --git a/prolog/problems/lists_advanced/max_2/en.py b/prolog/problems/lists_advanced/max_2/en.py index 59c00f0..fbdc612 100644 --- a/prolog/problems/lists_advanced/max_2/en.py +++ b/prolog/problems/lists_advanced/max_2/en.py @@ -2,7 +2,7 @@ name = 'max/2' slug = 'find the largest element in list' description = '''\ -<p><code>max(L, Max)</code>: <code>Max</code> is the largest value in the list <code>L</code>.</p> +<p><code>max(L, Max)</code>: <code>Max</code> is the largest value in list <code>L</code>.</p> <pre> ?- max([5,4,1,6], M). M = 6. @@ -10,4 +10,87 @@ description = '''\ M = 3. </pre>''' -hint = {} +plan = ['''\ +<p>As usual, try to reduce the problem to a smaller one. Say you already have <em>the largest</em> element +of the <em>tail</em>...</p> +''', '''\ +<p>Compare the largest element in the tail (list without head <code>H</code>) with the value of head <code>H</code>, +the larger of the two wins and gets returned.</p> +''', '''\ +<p>If the given list <code>L</code> is composed of head <code>H</code> and tail <code>T</code>, and if we +assume that some <code>MaxT</code> is the largest element in <code>T</code>, and if it's also true that +the value of <code>H</code> is greater than <code>MaxT</code>, then <code>H</code> is the largest element +in <code>L</code>. <em>Or</em> it is true that <code>H</code> is smaller than <code>MaxT</code>, and in this +case <code>MaxT</code> is the largest element in <code>L</code>.</p> +'''] + +hint = { + 'eq_instead_of_equ': '''\ +<p>The operator <code>==</code> is "stricter" than operator <code>=</code> in the sense that +for the latter it is enough to be able to make the two operands equal (unification). Perhaps by using <code>=</code> +you can make the predicate <code>max/2</code> more general (e.g. able to work with output arguments becoming inputs).</p> +<p>Of course, you can also solve the exercise without explicit use of either of these two operators, just +remember that unification is implicitly performed with the predicate's arguments (head of clause).</p> +''', + + 'eq_instead_of_equ_markup': '''\ +<p>Perhaps the operator for unification (=) would be better?</p> +''', + + 'base_case': '''\ +<p>Did you think of a base case? What's the shortest list with an obvious largest element?</p> +''', + + 'recursive_case': '''\ +<p>The base case is ok. However, what about the general recursive case?</p> +''', + + 'predicate_always_false': '''\ +<p>It seems your predicate is <emph>always</emph> "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>N</code> is equal to <code>N + 1</code>, +or something similarly impossible).</p> +''', + + 'timeout': '''\ +<p>Is there an infinite recursion at work here? How will it ever stop?</p> +<p>Or perhaps is there a missing, faulty, or simply incompatible (with the general recursive case) base case?</p> +''', + + 'empty_list_base_case': '''\ +<p>You'll be hard pressed to find the largest element of an empty list. What if you stop +the recursion a bit earlier this time?</p> +''', + + 'list_instead_of_elem_base_case': '''\ +<p>You should return an element, not a list!</p> +''', + + 'duplicates_not_covered': '''\ +<p>The list can contain duplicate elements. Did you think of that?</p> +''', + + 'args_not_instantiated': '''\ +<p>The error that prolog reported means that when it encountered an arithmetic operation, not all the +values were known.</p> +<p>Did you perhaps forget that conjunction has higher precedence that disjunction and that every prolog's +sentence (branch, rule) is independent in terms of the scope of the variables? This could be the problem. +Carefully inspect both blocks of code (before and after the semicolon) or both rules.</p> +''', + + 'unprotected_branch': '''\ +<p>It seems you didn't "protect" one of the (conditional) branches. Both branches (of the disjunction) typically +require a condition. Don't rely that if the execution reached the second branch that the first branch is false. +The relation between them is OR and not XOR. It's your job to make them mutually exclusive. Try the following +query and check <em>all possible</em> solutions and you'll notice the problem.</p> +<p><code>?- max([6,9,3,8,1], Max).</code></p> +''', + + 'one_branch_missing': '''\ +<p>Maybe you forgot one of the possibilities? The head can be <em>either</em> greater <em>or</em> smaller than +the largest element in the tail.</p> +''', +} diff --git a/prolog/problems/lists_advanced/max_2/sl.py b/prolog/problems/lists_advanced/max_2/sl.py index 0553e58..abd6cc5 100644 --- a/prolog/problems/lists_advanced/max_2/sl.py +++ b/prolog/problems/lists_advanced/max_2/sl.py @@ -11,7 +11,8 @@ description = '''\ </pre>''' plan = ['''\ -<p>Kot vedno, poskusi prevesti na manjši problem. Recimo, da že imaš <em>največji</em> element v repu seznama...</p> +<p>Kot vedno, poskusi prevesti na manjši problem. Recimo, da že imaš <em>največji</em> element v +<em>repu</em> seznama...</p> ''', '''\ <p>Največji element v repu (seznamu brez glave <code>H</code>) primerjaj z vrednostjo glave <code>H</code>, tisti, ki je večji zmaga in ga vrneš!</p> @@ -27,7 +28,7 @@ hint = { 'eq_instead_of_equ': '''\ <p>Operator <code>==</code> je strožji od operatorja <code>=</code> v smislu, da je za slednjega dovolj, da elementa lahko naredi enaka (unifikacija). Morda z uporabo <code>=</code> narediš predikat -<code>memb/2</code> delujoč tudi v kakšni drugi smeri.</p> +<code>max/2</code> delujoč tudi v kakšni drugi smeri.</p> <p>Seveda pa lahko nalogo rešiš brez obeh omenjenih operatorjev, spomni se, da lahko unifikacijo narediš implicitno že kar v argumentih predikata (glavi stavka).</p> ''', diff --git a/prolog/problems/lists_advanced/min_2/en.py b/prolog/problems/lists_advanced/min_2/en.py index a286cac..20677c6 100644 --- a/prolog/problems/lists_advanced/min_2/en.py +++ b/prolog/problems/lists_advanced/min_2/en.py @@ -1,8 +1,8 @@ name = 'min/2' -slug = 'find the smallest element' +slug = 'find the smallest element of a list' description = '''\ -<p><code>min(L, Min)</code>: <code>Min</code> is the smallest value in the list <code>L</code>.</p> +<p><code>min(L, Min)</code>: <code>Min</code> is the smallest value in list <code>L</code>.</p> <pre> ?- min([5,4,1,6], M). M = 1. @@ -10,4 +10,87 @@ description = '''\ M = 2. </pre>''' -hint = {} +plan = ['''\ +<p>As usual, try to reduce the problem to a smaller one. Say you already have <em>the smallest</em> element +of the <em>tail</em>...</p> +''', '''\ +<p>Compare the smallest element in the tail (list without head <code>H</code>) with the value of head <code>H</code>, +the smaller of the two wins and gets returned.</p> +''', '''\ +<p>If the given list <code>L</code> is composed of head <code>H</code> and tail <code>T</code>, and if we +assume that some <code>MinT</code> is the smallest element in <code>T</code>, and if it's also true that +the value of <code>H</code> is smaller than <code>MinT</code>, then <code>H</code> is the smallest element +in <code>L</code>. <em>Or</em> it is true that <code>H</code> is greater than <code>MinT</code>, and in this +case <code>MinT</code> is the smallest element in <code>L</code>.</p> +'''] + +hint = { + 'eq_instead_of_equ': '''\ +<p>The operator <code>==</code> is "stricter" than operator <code>=</code> in the sense that +for the latter it is enough to be able to make the two operands equal (unification). Perhaps by using <code>=</code> +you can make the predicate <code>min/2</code> more general (e.g. able to work with output arguments becoming inputs).</p> +<p>Of course, you can also solve the exercise without explicit use of either of these two operators, just +remember that unification is implicitly performed with the predicate's arguments (head of clause).</p> +''', + + 'eq_instead_of_equ_markup': '''\ +<p>Perhaps the operator for unification (=) would be better?</p> +''', + + 'base_case': '''\ +<p>Did you think of a base case? What's the shortest list with an obvious smallest element?</p> +''', + + 'recursive_case': '''\ +<p>The base case is ok. However, what about the general recursive case?</p> +''', + + 'predicate_always_false': '''\ +<p>It seems your predicate is <emph>always</emph> "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>N</code> is equal to <code>N + 1</code>, +or something similarly impossible).</p> +''', + + 'timeout': '''\ +<p>Is there an infinite recursion at work here? How will it ever stop?</p> +<p>Or perhaps is there a missing, faulty, or simply incompatible (with the general recursive case) base case?</p> +''', + + 'empty_list_base_case': '''\ +<p>You'll be hard pressed to find the smallest element of an empty list. What if you stop +the recursion a bit earlier this time?</p> +''', + + 'list_instead_of_elem_base_case': '''\ +<p>You should return an element, not a list!</p> +''', + + 'duplicates_not_covered': '''\ +<p>The list can contain duplicate elements. Did you think of that?</p> +''', + + 'args_not_instantiated': '''\ +<p>The error that prolog reported means that when it encountered an arithmetic operation, not all the +values were known.</p> +<p>Did you perhaps forget that conjunction has higher precedence that disjunction and that every prolog's +sentence (branch, rule) is independent in terms of the scope of the variables? This could be the problem. +Carefully inspect both blocks of code (before and after the semicolon) or both rules.</p> +''', + + 'unprotected_branch': '''\ +<p>It seems you didn't "protect" one of the (conditional) branches. Both branches (of the disjunction) typically +require a condition. Don't rely that if the execution reached the second branch that the first branch is false. +The relation between them is OR and not XOR. It's your job to make them mutually exclusive. Try the following +query and check <em>all possible</em> solutions and you'll notice the problem.</p> +<p><code>?- min([1,9,3,8,6], Min).</code></p> +''', + + 'one_branch_missing': '''\ +<p>Maybe you forgot one of the possibilities? The head can be <em>either</em> greater <em>or</em> smaller than +the smallest element in the tail.</p> +''', +} diff --git a/prolog/problems/lists_advanced/min_2/sl.py b/prolog/problems/lists_advanced/min_2/sl.py index bac4dc6..4a6975e 100644 --- a/prolog/problems/lists_advanced/min_2/sl.py +++ b/prolog/problems/lists_advanced/min_2/sl.py @@ -1,5 +1,5 @@ name = 'min/2' -slug = 'Poišči najmanjši element v danem seznamu' +slug = 'Poišči najmanjši element v seznamu' description = '''\ <p><code>min(L, Min)</code>: <code>Min</code> je najmanjši element v seznamu <code>L</code>.</p> @@ -11,7 +11,8 @@ description = '''\ </pre>''' plan = ['''\ -<p>Kot vedno, poskusi prevesti na manjši problem. Recimo, da že imaš <em>najmanjši</em> element v repu seznama...</p> +<p>Kot vedno, poskusi prevesti na manjši problem. Recimo, da že imaš <em>najmanjši</em> element v +<em>repu</em> seznama...</p> ''', '''\ <p>Najmanjši element v repu (seznamu brez glave <code>H</code>) primerjaj z vrednostjo glave <code>H</code>, tisti, ki je manjši zmaga in ga vrneš!</p> @@ -27,7 +28,7 @@ hint = { 'eq_instead_of_equ': '''\ <p>Operator <code>==</code> je strožji od operatorja <code>=</code> v smislu, da je za slednjega dovolj, da elementa lahko naredi enaka (unifikacija). Morda z uporabo <code>=</code> narediš predikat -<code>memb/2</code> delujoč tudi v kakšni drugi smeri.</p> +<code>min/2</code> delujoč tudi v kakšni drugi smeri.</p> <p>Seveda pa lahko nalogo rešiš brez obeh omenjenih operatorjev, spomni se, da lahko unifikacijo narediš implicitno že kar v argumentih predikata (glavi stavka).</p> ''', |