summaryrefslogtreecommitdiff
path: root/prolog/problems/lists/insert_3/common.py
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-10 01:32:27 +0100
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-10 01:32:27 +0100
commit0cb99edad42fb4e383599dd56dc8db12bf8d40cc (patch)
tree574593dfaccd1a02c1ef2aca7fd78fdbbcadb6a0 /prolog/problems/lists/insert_3/common.py
parent8ef87d4610b575c9b1e7e31751663ab7933eefeb (diff)
Hints for insert/3 added.
Diffstat (limited to 'prolog/problems/lists/insert_3/common.py')
-rw-r--r--prolog/problems/lists/insert_3/common.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/prolog/problems/lists/insert_3/common.py b/prolog/problems/lists/insert_3/common.py
index 5b049f7..3b56cf3 100644
--- a/prolog/problems/lists/insert_3/common.py
+++ b/prolog/problems/lists/insert_3/common.py
@@ -26,10 +26,11 @@ hint_type = {
'predicate_always_false': Hint('predicate_always_false'),
'base_case': Hint('base_case'),
'timeout': Hint('timeout'),
- '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'),
+ 'ins_results_in_empty_list': Hint('ins_results_in_empty_list'),
+ 'ins_results_in_arbitrary_result': Hint('ins_results_in_arbitrary_result'),
}
test_cases = [
@@ -77,34 +78,35 @@ def hint(code, aux_code):
# recursion is getting bigger and bigger
- # deleting from empty list succeeds with an emtpy list result
- if prolog.engine.ask_truthTO(engine_id, 'del(_, [], _)'):
- return [{'id': 'del_from_empty_list_success'}]
+ # inserting an element succeeds with an emtpy list result
+ if prolog.engine.ask_truthTO(engine_id, 'insert(_, _, [])'):
+ return [{'id': 'ins_results_in_empty_list'}]
+
+ # inserting an element succeeds with an arbitrary result
+ if prolog.engine.ask_truth(engine_id, 'insert(_, _, L), var(L)'):
+ return [{'id': 'ins_results_in_arbitrary_result'}]
# missing/failed base case
- if not prolog.engine.ask_one(engine_id, 'del(qQ, [qQ,qa,qb,qc], [qa,qb,qc])'):
+ if not prolog.engine.ask_one(engine_id, 'insert(qQ, [qa,qb,qc], [qQ,qa,qb,qc])'):
return [{'id': 'base_case'}]
# target predicate seems to always be false
- if not prolog.engine.ask_truth(engine_id, 'del(_, [_,_,_,_,_,_], _)'):
+ if not prolog.engine.ask_truth(engine_id, 'insert(_, [_,_,_,_,_,_], _)'):
return [{'id': 'predicate_always_false'}]
# forgot to put list head(s) back in the list when deleting an element
- if prolog.engine.ask_truth(engine_id, 'del(q, [a,b,c,d,q,x,y,z], [x,y,z])'):
+ if prolog.engine.ask_truth(engine_id, 'insert(q, [a,b,c,d,x,y,z], [q,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, \
- 'findall(NL, del(q, [q,q,q,a,b,c], NL), [[q,q,a,b,c],[q,q,a,b,c],[q,q,a,b,c]]).') and \
- not prolog.engine.ask_truth(engine_id, 'del(q, [a,b,c,q,x,y,z], [a,b,c,x,y,z])'):
+ 'findall(NL, insert(q, [a,b,c], NL), [[q,a,b,c], [q,q,b,c], [q,q,q,c], [q,q,q,q]]).') and \
+ not prolog.engine.ask_truth(engine_id, 'insert(q, [a,b,c,x,y,z], [a,b,c,q,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)
-
# base case works, the recursive doesn't (but it doesn't timeout)
# this may be left as the last, most generic hint
- if not prolog.engine.ask_truth(engine_id, 'del(qQ, [qa,qb,qQ,qc], [qa,qb,qc])'):
+ if not prolog.engine.ask_truth(engine_id, 'insert(qQ, [qa,qb,qc], [qa,qb,qQ,qc])'):
return [{'id': 'recursive_case'}]