summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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>