summaryrefslogtreecommitdiff
path: root/prolog/problems/family_relations/descendant_2
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-01 01:09:07 +0100
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-01 01:09:07 +0100
commit80881f3a6b05474fcd5afe7b3ed30cc7e75e4a92 (patch)
tree61c3d0e0fd6abc7110fb21bd7aacaa0efc3a1c38 /prolog/problems/family_relations/descendant_2
parentf99c7db178964f641a422d4ad7cbe60e1483f3e5 (diff)
Improved hints for ancestor/2 and descendant/2.
Diffstat (limited to 'prolog/problems/family_relations/descendant_2')
-rw-r--r--prolog/problems/family_relations/descendant_2/common.py19
-rw-r--r--prolog/problems/family_relations/descendant_2/sl.py4
2 files changed, 14 insertions, 9 deletions
diff --git a/prolog/problems/family_relations/descendant_2/common.py b/prolog/problems/family_relations/descendant_2/common.py
index d2a2dcb..4c7f8e3 100644
--- a/prolog/problems/family_relations/descendant_2/common.py
+++ b/prolog/problems/family_relations/descendant_2/common.py
@@ -29,6 +29,7 @@ hint_type = {
'descendant_of_oneself': Hint('ancestor_to_oneself'),
'descendant_need_not_be_parent': Hint('descendant_need_not_be_parent'),
'wrong_direction': Hint('wrong_direction'),
+ 'timeout': Hint('timeout'),
}
test_cases = [
@@ -84,28 +85,28 @@ def hint(code, aux_code):
# missing/failed base case
# TODO: how will ask_truth handle/return timeouts...
# TODO: timeout is the same as fail in this particular case
- if prolog.engine.ask_truth(engine_id,
+ if prolog.engine.ask_truthTO(engine_id,
'parent(Y, X), \+ descendant(X, Y)'):
return [{'id': 'base_case'}]
# descendant of oneself
- if prolog.engine.ask_truth(engine_id, 'descendant(X, X)'):
+ if prolog.engine.ask_truthTO(engine_id, 'descendant(X, X)'):
return [{'id': 'descendant_of_oneself'}]
- # X does not necessarily need to be a parent
- if prolog.engine.ask_one(engine_id,
- 'descendant(X, _), \+ parent(X, _)') == 'false':
- return [{'id': 'descendant_need_not_be_parent'}]
-
# ancestor instead of descendant (wrong direction)
# warning: knowledge base dependent
- if prolog.engine.ask_truth(engine_id,
+ if prolog.engine.ask_truthTO(engine_id,
'findall(_, descendant(william, X), L1), length(L1, 6), \
findall(_, descendant(X, william), L2), length(L2, 2)'):
return [{'id': 'wrong_direction'}]
+ # X does not necessarily need to be a parent
+ if prolog.engine.ask_one(engine_id,
+ 'descendant(X, _), \+ parent(X, _)') == 'false':
+ return [{'id': 'descendant_need_not_be_parent'}]
+
except socket.timeout as ex:
- pass
+ return [{'id': 'timeout'}]
finally:
if engine_id:
diff --git a/prolog/problems/family_relations/descendant_2/sl.py b/prolog/problems/family_relations/descendant_2/sl.py
index 8774ad6..949280f 100644
--- a/prolog/problems/family_relations/descendant_2/sl.py
+++ b/prolog/problems/family_relations/descendant_2/sl.py
@@ -60,6 +60,10 @@ Skratka, poskusi prevesti na "manjši" problem, npr. potomec v enem koraku manj
<p>Potomec <code>X</code> pravzaprav ne rabi imeti otrok...</p>
''',
+ 'timeout': '''\
+<p>Je morda na delu potencialno neskončna rekurzija?</p>
+''',
+
'wrong_direction': '''\
<p>Si morda sprogramiral ravno obratno in zamenjal prednika s potomcem?
<code>X</code> naj bo potomec od <code>Y</code> in ne obratno!</p>