diff options
Diffstat (limited to 'prolog/problems/lists/dup_2')
-rw-r--r-- | prolog/problems/lists/dup_2/common.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/prolog/problems/lists/dup_2/common.py b/prolog/problems/lists/dup_2/common.py index 0ed3914..6e31690 100644 --- a/prolog/problems/lists/dup_2/common.py +++ b/prolog/problems/lists/dup_2/common.py @@ -77,15 +77,6 @@ def hint(code, aux_code): # recursion is getting bigger and bigger - # forcing result onto recursion; case of dup(T, [H,H|L]) or dup(T, [H,H|T]) - if not prolog.engine.ask_truthTO(engine_id, 'dup([a,b,c,d,e], _)') and \ - (prolog.engine.ask_truth(engine_id, - 'asserta( dup([b], [a,a,yowza]) ), dup([a,b], [yowza]), retract( dup([b], [a,a,yowza]) )') or \ - prolog.engine.ask_truth(engine_id, - 'asserta( dup([b], [a,a,b]) ), dup([a,b], [b]), retract( dup([b], [a,a,b]) )')): - return [{'id': 'forcing_result_onto_recursion'}] - - # base case succeeds with arbitrary result if prolog.engine.ask_truthTO(engine_id, 'dup([], L), var(L)'): return [{'id': 'base_case_arbitrary'}] @@ -94,6 +85,14 @@ def hint(code, aux_code): if prolog.engine.ask_truthTO(engine_id, 'dup([q], [q,q]), \+ dup([], [])'): return [{'id': 'base_case_missing_[]'}] + # forcing result onto recursion; case of dup(T, [H,H|L]) or dup(T, [H,H|T]) + if not prolog.engine.ask_truthTO(engine_id, 'dup([a,b,c,d,e], _)') and \ + (prolog.engine.ask_truth(engine_id, + 'asserta( dup([b], [a,a,yowza]) ), dup([a,b], [yowza]), retract( dup([b], [a,a,yowza]) )') or \ + prolog.engine.ask_truth(engine_id, + 'asserta( dup([b], [a,a,b]) ), dup([a,b], [b]), retract( dup([b], [a,a,b]) )')): + return [{'id': 'forcing_result_onto_recursion'}] + # missing/failed base case if not prolog.engine.ask_one(engine_id, 'dup([], [])'): return [{'id': 'base_case'}] |