summaryrefslogtreecommitdiff
path: root/prolog/problems/lists/memb_2
diff options
context:
space:
mode:
authorMartin Možina <martin.mozina@fri.uni-lj.si>2016-09-27 15:19:07 +0200
committerMartin Možina <martin.mozina@fri.uni-lj.si>2016-09-27 15:19:07 +0200
commit01eb98c7a5e86325e1243f0d0f4e111a18d1e535 (patch)
tree7871a2a0d30fd7761b6ac0f40846fbd004e10b25 /prolog/problems/lists/memb_2
parent5a00cf460426af73cb1fef953acf01f460887f77 (diff)
parent3bfcb3e651980f1675807b8f82826dcb3e4e1013 (diff)
Merge branch 'master' of 192.168.15.97:codeq-problems
Diffstat (limited to 'prolog/problems/lists/memb_2')
-rw-r--r--prolog/problems/lists/memb_2/en.py68
1 files changed, 67 insertions, 1 deletions
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>
+''',
+}