From d1565072c4d1eefcaf294bebfdb9ce1a3d299485 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Wed, 9 Mar 2016 20:32:53 +0100 Subject: Hints for del/3 updated. --- prolog/problems/lists/del_3/common.py | 5 +++++ prolog/problems/lists/del_3/sl.py | 8 ++++++++ 2 files changed, 13 insertions(+) (limited to 'prolog/problems') 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 @@ -78,6 +78,14 @@ saj veš, da z največjim veseljem reče "no"! :)

Si pozabil dati glavo nazaj na začetek seznama, ko se vračaš iz rekurzije?

Poskusi postaviti naslednje vprašanje prologu:

?- del(d, [a,b,c,d,e,f,g], L).

+''', + + 'leading_heads_all_x': '''\ +

Si morda pozabil (copy/paste?) in uporabil [X|T] namesto bolj splošnega +[H|T] v rekurzivnem primeru?

+

Od spodnjih dveh vprašanj prologu prvo deluje, drugo pa ne.

+

?- del(d, [d,d,d,d,e,f,g], L).

+

?- del(d, [a,b,c,d,e,f,g], L).

''', 'final_hint': '''\ -- cgit v1.2.1