summaryrefslogtreecommitdiff
path: root/prolog
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-08-28 23:07:01 +0200
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-08-28 23:07:01 +0200
commit918513a870273ab70e6ea60ab25344b77a44fec3 (patch)
tree4beb23128ed1e28dacc5dbebcd2ec51f1f786e17 /prolog
parentca743bffb497dea794950bf2bbda45e3bb4c936b (diff)
English translation for memb/2 added.
Diffstat (limited to 'prolog')
-rw-r--r--prolog/problems/lists/conc_3/en.py2
-rw-r--r--prolog/problems/lists/memb_2/en.py68
2 files changed, 68 insertions, 2 deletions
diff --git a/prolog/problems/lists/conc_3/en.py b/prolog/problems/lists/conc_3/en.py
index 2e74e5e..c384222 100644
--- a/prolog/problems/lists/conc_3/en.py
+++ b/prolog/problems/lists/conc_3/en.py
@@ -30,7 +30,7 @@ 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>rev/2</code> more general (e.g. able to work with output arguments becoming inputs).</p>
+you can make the predicate <code>conc/3</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>
''',
diff --git a/prolog/problems/lists/memb_2/en.py b/prolog/problems/lists/memb_2/en.py
index ae62825..681c18a 100644
--- a/prolog/problems/lists/memb_2/en.py
+++ b/prolog/problems/lists/memb_2/en.py
@@ -12,4 +12,70 @@ description = '''\
X = 1.
</pre>'''
-hint = {}
+plan = ['''\
+<p>Where can we find the searched for element <code>X</code>? Remember that the list has two parts: the head and
+the tail. Therefore, there are two possibilies! ;)</p>
+''', '''\
+<p><img src="[%@resource base_case.svg%]" /></p>
+<p>In prolog we can understand a list like a queue of people waiting for a bus. The driver only sees
+the first person in the queue, the others are hidden in the list's tail. So the element <code>X</code>
+can either be at the start of the queue or...</p>
+''', '''\
+<p>It's easy to look at ("search for") the head of the list. But how do we search the tail? Simply,
+we remove the first element and repeat the search with the smaller list (tail). If <code>[H|T]</code>
+is our whole list, then <code>T</code> is this same list without the first element.
+Since the new list (tail) is smaller, we reduced the problem and thus facilitated the use of recursion.</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>memb/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><img src="[%@resource base_case.svg%]" /></p>
+<p>Did you think of a base case? What is the simplest possible case if the element is present in the list?
+Which element in the list is the easiest to access?</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 an empty list <code>[]</code> is equal to a list with
+exactly three elements <code>[A,B,C]</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>
+''',
+
+ 'final_hint': '''\
+<p>Predicate <code>memb/2</code> is useful for much more than just checking whether a list contains
+a given element or not. Actually, most of the time, it's used in "a different direction" as
+"return some element <code>X</code> from list <code>L</code>". In fact you've just written yourself
+a generator of elements from the list.</p>
+<p>Try the following query:</p>
+<p><code>?- memb(Coin, [1,2,5,10,20,50,100,200]).</code></p>
+<p>or this one:</p>
+<p><code>?- memb(Operator, [+, -, *, /]).</code></p>
+<p>Can you form a query to ask prolog how do we get a sum of 30 cents with exactly three coins?
+The operator <code>=:=</code> is used to check for arithmetic equality. How many solutions are there? ;)</p>
+''',
+}