summaryrefslogtreecommitdiff
path: root/prolog/problems/lists/last_elem_2
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-14 03:44:53 +0100
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-14 03:44:53 +0100
commita4e8456ab5f14a34cb2f79c0946c439a976041f8 (patch)
tree2dfff81e3337c4423284ec6260e9db22c70bc38a /prolog/problems/lists/last_elem_2
parenta2ef91e85018538be2b82fa085320f518abe254a (diff)
Hints for last_elem/2 added.
Diffstat (limited to 'prolog/problems/lists/last_elem_2')
-rw-r--r--prolog/problems/lists/last_elem_2/common.py17
-rw-r--r--prolog/problems/lists/last_elem_2/sl.py13
2 files changed, 28 insertions, 2 deletions
diff --git a/prolog/problems/lists/last_elem_2/common.py b/prolog/problems/lists/last_elem_2/common.py
index 8c08d61..75cec75 100644
--- a/prolog/problems/lists/last_elem_2/common.py
+++ b/prolog/problems/lists/last_elem_2/common.py
@@ -26,6 +26,9 @@ hint_type = {
'recursive_case': Hint('recursive_case'),
'timeout': Hint('timeout'),
'final_hint': Hint('final_hint'),
+ '[]_should_not_succeed': Hint('[]_should_not_succeed'),
+ 'list_returned': Hint('list_returned'),
+ 'clumsy_conc_use': Hint('clumsy_conc_use'),
}
test_cases = [
@@ -74,6 +77,18 @@ def hint(code, aux_code):
# recursion is getting bigger and bigger
+ # succeeds when asked to return the last element of an empty list
+ if prolog.engine.ask_truthTO(engine_id, 'last_elem([], _)'):
+ return [{'id': '[]_should_not_succeed'}]
+
+ # using conc, but clumsily: conc(_, X, L) instead of conc(_, [X], L)
+ if prolog.util.Token('NAME', 'conc') in tokens and \
+ prolog.engine.ask_truthTO(engine_id, 'last_elem([q,a,b,c], [q,a,b,c])'):
+ return [{'id': 'clumsy_conc_use'}]
+
+ # returns a list, not an element as required
+ if prolog.engine.ask_truthTO(engine_id, 'last_elem([q], X), is_list(X)'):
+ return [{'id': 'list_returned'}]
# missing/failed base case
if not prolog.engine.ask_truthTO(engine_id, 'last_elem([qQ], qQ)'):
@@ -89,8 +104,6 @@ def hint(code, aux_code):
if not prolog.engine.ask_truth(engine_id, 'last_elem([qa,qb,qQ,qc], qc)'):
return [{'id': 'recursive_case'}]
- # TODO: Tim, can we include 'fail'-used as a general hint?
-
except socket.timeout as ex:
return [{'id': 'timeout'}]
diff --git a/prolog/problems/lists/last_elem_2/sl.py b/prolog/problems/lists/last_elem_2/sl.py
index c0d8082..bcc33f8 100644
--- a/prolog/problems/lists/last_elem_2/sl.py
+++ b/prolog/problems/lists/last_elem_2/sl.py
@@ -38,6 +38,19 @@ implicitno že kar v argumentih predikata (glavi stavka).</p>
<p>Si pomislil na robni pogoj? Kaj je najbolj enostaven primer? Kaj, če ima seznam samo en element?</p>
''',
+ '[]_should_not_succeed': '''\
+<p>Kako si lahko uspešno našel zadnji element v praznem seznamu? Verjetno potrebuješ drugačen robni pogoj.</p>
+''',
+
+ 'list_returned': '''\
+<p>Vračaš seznam namesto elementa.</p>
+''',
+
+ 'clumsy_conc_use': '''\
+<p>Uporabljaš <code>conc/3</code>? Zanimiva ideja. Ne pozabi, da mora drugi seznam, ki ga konkateniraš
+biti dolžine ena, če hočeš doseči to kar želiš. Torej vzorec oblike <code>[X]</code>, kajne?</p>
+''',
+
'recursive_case': '''\
<p>Robni primer deluje. Kaj pa rekurzivni, splošni, primer?</p>
''',