summaryrefslogtreecommitdiff
path: root/prolog/problems/family_relations/descendant_2
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-02 01:36:02 +0100
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-02 01:36:02 +0100
commitcfbd840591f3b334790ab22daa3cb7b9c49ebc9c (patch)
tree0d8ed9dae561ce04b252d6d52e9b746d6583eaac /prolog/problems/family_relations/descendant_2
parent80881f3a6b05474fcd5afe7b3ed30cc7e75e4a92 (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.py13
-rw-r--r--prolog/problems/family_relations/descendant_2/sl.py23
2 files changed, 27 insertions, 9 deletions
diff --git a/prolog/problems/family_relations/descendant_2/common.py b/prolog/problems/family_relations/descendant_2/common.py
index 4c7f8e3..70936da 100644
--- a/prolog/problems/family_relations/descendant_2/common.py
+++ b/prolog/problems/family_relations/descendant_2/common.py
@@ -27,9 +27,11 @@ hint_type = {
'grandparent_used_markup': HintPopup('grandparent_used_markup'),
'base_case': Hint('base_case'),
'descendant_of_oneself': Hint('ancestor_to_oneself'),
+ 'descendant_of_oneself_with_or': Hint('descendant_of_oneself_with_or'),
'descendant_need_not_be_parent': Hint('descendant_need_not_be_parent'),
'wrong_direction': Hint('wrong_direction'),
'timeout': Hint('timeout'),
+ 'final_hint': Hint('final_hint'),
}
test_cases = [
@@ -58,6 +60,10 @@ def test(code, aux_code):
prolog.engine.destroy(engine_id)
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ if n_correct == len(test_cases):
+ tokens = prolog.util.tokenize(code)
+ if prolog.util.Token('NAME', 'ancestor') not in tokens:
+ hints += [{'id': 'final_hint'}]
return n_correct, len(test_cases), hints
def hint(code, aux_code):
@@ -83,15 +89,16 @@ def hint(code, aux_code):
[{'id': 'grandparent_used'}]
# 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_truthTO(engine_id,
'parent(Y, X), \+ descendant(X, Y)'):
return [{'id': 'base_case'}]
# descendant of oneself
if prolog.engine.ask_truthTO(engine_id, 'descendant(X, X)'):
- return [{'id': 'descendant_of_oneself'}]
+ if prolog.util.Token('SEMI', ';') in tokens:
+ return [{'id': 'descendant_of_oneself_with_or'}]
+ else:
+ return [{'id': 'descendant_of_oneself'}]
# ancestor instead of descendant (wrong direction)
# warning: knowledge base dependent
diff --git a/prolog/problems/family_relations/descendant_2/sl.py b/prolog/problems/family_relations/descendant_2/sl.py
index 949280f..2b638fd 100644
--- a/prolog/problems/family_relations/descendant_2/sl.py
+++ b/prolog/problems/family_relations/descendant_2/sl.py
@@ -48,12 +48,22 @@ Skratka, poskusi prevesti na "manjši" problem, npr. potomec v enem koraku manj
''',
'base_case': '''\
-<p>Si pomislil na robni pogoj? Kaj je najbolj enostaven par (potomec, prednik)?</p>
+<p>Si pomislil na robni pogoj? Rekurzija se mora enkrat tudi ustaviti.
+Kaj je najbolj enostaven par (potomec, prednik)?</p>
<p><img src="[%@resource Prolog_descendant_01.svg%]" /></p>
''', # TODO: morda ta hint naredim z "more": najprej tekst, ob kliku pa še slika... (sicer je preveč očitno)
'descendant_of_oneself': '''\
-<p>Kako je lahko nekdo potomec samega sebe?</p>
+<p>Kako je lahko nekdo potomec samega sebe? Premisli, morda se ti splača tudi grafično skicirati
+tvojo trenutno rešitev.</p>
+''',
+
+ 'descendant_of_oneself_with_or': '''\
+<p>Kako je lahko nekdo potomec samega sebe? Premisli, morda se ti splača tudi grafično skicirati
+tvojo trenutno rešitev.</p>
+<p>Morda se ti splača preveriti tudi uporabo podpičja. To praktično naredi dva ločena stavka oz. veji
+(eno ali drugo velja, morda tudi oboje). Vendar pazi, ker sta ti dve veji med seboj neodvisni
+-- vrednosti iz ene se ne prenašajo v drugo vejo.</p>
''',
'descendant_need_not_be_parent': '''\
@@ -61,7 +71,8 @@ Skratka, poskusi prevesti na "manjši" problem, npr. potomec v enem koraku manj
''',
'timeout': '''\
-<p>Je morda na delu potencialno neskončna rekurzija?</p>
+<p>Je morda na delu potencialno neskončna rekurzija? Kako se bo ustavila?</p>
+</p>Morda pa je kriv tudi manjkajoč, neustrezen ali preprosto nekompatibilen (s splošnim primerom) robni pogoj?</p>
''',
'wrong_direction': '''\
@@ -70,10 +81,10 @@ Skratka, poskusi prevesti na "manjši" problem, npr. potomec v enem koraku manj
<p><img src="[%@resource Prolog_descendant_02.svg%]" /></p>
''', # TODO: Tim, kako bi lahko še query poslali med parametri v Hint dict? Je to predvideno? Tukaj bi recimo pasalo...
- 'interesting_tidbit': '''\
-<p>Zanimivost: nalogo bi lahko rešil tudi z uporabo rešitve za relacijo "ancestor".
+ 'final_hint': '''\
+<p>Zanimivost: nalogo bi lahko rešil tudi z uporabo rešitve za relacijo <code>ancestor/2</code>.
Samo obrni spremenljivki <code>X</code> in <code>Y</code>;
če je <code>X</code> potomec od <code>Y</code>, potem je <code>Y</code> prednik od <code>X</code>.</p>
-''', # TODO: trigger za interesting tidbit
+''',
}