summaryrefslogtreecommitdiff
path: root/prolog
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-09 20:32:53 +0100
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-09 20:32:53 +0100
commitd1565072c4d1eefcaf294bebfdb9ce1a3d299485 (patch)
tree72cdf032dd01e1085446669150eff0e02fe70ca1 /prolog
parent4fd77108854d7e83ce2d7135ed02b65ba73fc9e9 (diff)
Hints for del/3 updated.
Diffstat (limited to 'prolog')
-rw-r--r--prolog/problems/lists/del_3/common.py5
-rw-r--r--prolog/problems/lists/del_3/sl.py8
2 files changed, 13 insertions, 0 deletions
diff --git a/prolog/problems/lists/del_3/common.py b/prolog/problems/lists/del_3/common.py
index 125ece1..65c51d1 100644
--- a/prolog/problems/lists/del_3/common.py
+++ b/prolog/problems/lists/del_3/common.py
@@ -28,6 +28,7 @@ hint_type = {
'del_from_empty_list_success': Hint('del_from_empty_list_success'),
'lost_heads': Hint('lost_heads'),
'recursive_case': Hint('recursive_case'),
+ 'leading_heads_all_x': Hint('leading_heads_all_x'),
}
test_cases = [
@@ -95,6 +96,10 @@ def hint(code, aux_code):
if prolog.engine.ask_truth(engine_id, 'del(q, [a,b,c,d,q,x,y,z], [x,y,z])'):
return [{'id': 'lost_heads'}]
+ # used [X|T] instead of more general [H|T] in recursive case
+ if prolog.engine.ask_truth(engine_id, 'del(q, [a,b,c,d,q,x,y,z], [x,y,z])'):
+ return [{'id': 'leading_heads_all_x'}]
+
# L=[H|T] at the end of the rule; this can be detected with test cases and can be wrong (in some sense)
# TODO: implement it, and provide a good explanation (might be hard)
diff --git a/prolog/problems/lists/del_3/sl.py b/prolog/problems/lists/del_3/sl.py
index ce82732..df5e014 100644
--- a/prolog/problems/lists/del_3/sl.py
+++ b/prolog/problems/lists/del_3/sl.py
@@ -80,6 +80,14 @@ Si pozabil dati glavo nazaj na začetek seznama, ko se vračaš iz rekurzije?</p
<p><code>?- del(d, [a,b,c,d,e,f,g], L).</code></p>
''',
+ 'leading_heads_all_x': '''\
+<p>Si morda pozabil (copy/paste?) in uporabil <code>[X|T]</code> namesto bolj splošnega
+<code>[H|T]</code> v rekurzivnem primeru?</p>
+<p>Od spodnjih dveh vprašanj prologu prvo deluje, drugo pa ne.</p>
+<p><code>?- del(d, [d,d,d,d,e,f,g], L).</code></p>
+<p><code>?- del(d, [a,b,c,d,e,f,g], L).</code></p>
+''',
+
'final_hint': '''\
<p>Zanimivost: operaciji vstavljanja in brisanja iz seznama sta si ravno nasprotni. Če se malce poigraš z
argumenti, lahko <code>del/3</code> rešiš kar z <code>insert/3</code>.</p>