summaryrefslogtreecommitdiff
path: root/prolog/problems/lists/dup_2
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-11 19:58:03 +0100
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-11 19:58:03 +0100
commit8a9f429b6c126e00af8d5f2650d6c4d705917b6a (patch)
tree4a1002a423b7802b05b693445372c895c5d531f7 /prolog/problems/lists/dup_2
parent053be5a6671a765b4adaa5f54f90504007ecac30 (diff)
Plans for conc/3 added. Order of hints in dup/2 corrected.
Diffstat (limited to 'prolog/problems/lists/dup_2')
-rw-r--r--prolog/problems/lists/dup_2/common.py17
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'}]