From 86bfc55d2ddc19b79127f2c788609635b702dbfd Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Sat, 17 Oct 2015 20:04:54 +0200 Subject: Family relations section fully hint-ready (just a few minor things missing). --- .../descendant_2/Prolog_descendant_01.svg | 374 +++++++ .../descendant_2/Prolog_descendant_02.svg | 283 +++++ .../descendant_2/Prolog_descendant_03.svg | 899 ++++++++++++++++ .../descendant_2/Prolog_descendant_04.svg | 1090 ++++++++++++++++++++ .../family_relations/descendant_2/common.py | 33 +- .../problems/family_relations/descendant_2/sl.py | 24 +- 6 files changed, 2682 insertions(+), 21 deletions(-) create mode 100644 prolog/problems/family_relations/descendant_2/Prolog_descendant_01.svg create mode 100644 prolog/problems/family_relations/descendant_2/Prolog_descendant_02.svg create mode 100644 prolog/problems/family_relations/descendant_2/Prolog_descendant_03.svg create mode 100644 prolog/problems/family_relations/descendant_2/Prolog_descendant_04.svg (limited to 'prolog/problems/family_relations/descendant_2') diff --git a/prolog/problems/family_relations/descendant_2/Prolog_descendant_01.svg b/prolog/problems/family_relations/descendant_2/Prolog_descendant_01.svg new file mode 100644 index 0000000..a81be29 --- /dev/null +++ b/prolog/problems/family_relations/descendant_2/Prolog_descendant_01.svg @@ -0,0 +1,374 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prolog/problems/family_relations/descendant_2/Prolog_descendant_02.svg b/prolog/problems/family_relations/descendant_2/Prolog_descendant_02.svg new file mode 100644 index 0000000..210b4bc --- /dev/null +++ b/prolog/problems/family_relations/descendant_2/Prolog_descendant_02.svg @@ -0,0 +1,283 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prolog/problems/family_relations/descendant_2/Prolog_descendant_03.svg b/prolog/problems/family_relations/descendant_2/Prolog_descendant_03.svg new file mode 100644 index 0000000..ad5ed94 --- /dev/null +++ b/prolog/problems/family_relations/descendant_2/Prolog_descendant_03.svg @@ -0,0 +1,899 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prolog/problems/family_relations/descendant_2/Prolog_descendant_04.svg b/prolog/problems/family_relations/descendant_2/Prolog_descendant_04.svg new file mode 100644 index 0000000..19f5b26 --- /dev/null +++ b/prolog/problems/family_relations/descendant_2/Prolog_descendant_04.svg @@ -0,0 +1,1090 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prolog/problems/family_relations/descendant_2/common.py b/prolog/problems/family_relations/descendant_2/common.py index cfa1d37..49e7e5c 100644 --- a/prolog/problems/family_relations/descendant_2/common.py +++ b/prolog/problems/family_relations/descendant_2/common.py @@ -4,7 +4,7 @@ from operator import itemgetter import socket import prolog.engine import prolog.util -from server.hints import Hint, HintSequence +from server.hints import Hint, HintPopup import server.problems id = 101 @@ -21,8 +21,10 @@ descendant(X, Y) :- ''' hint_type = { + 'gender_is_irrelevant_markup': HintPopup('gender_is_irrelevant_markup'), 'gender_is_irrelevant': Hint('gender_is_irrelevant'), 'grandparent_used': Hint('grandparent_used'), + 'grandparent_used_markup': HintPopup('grandparent_used_markup'), 'base_case': Hint('base_case'), 'descendant_of_oneself': Hint('ancestor_to_oneself'), 'descendant_need_not_be_parent': Hint('descendant_need_not_be_parent'), @@ -30,7 +32,12 @@ hint_type = { } test_cases = [ - # TODO + ('descendant(anna, X)', + [{'X': 'jerry'}, {'X': 'elaine'}, {'X': 'morty'}, {'X': 'helen'}]), + ('descendant(daniela, X)', + [{'X': 'nevia'}, {'X': 'aleksander'}, {'X': 'margaret'}, {'X': 'ana'}, {'X': 'aleksandr'}]), + ('descendant(X, william)', + [{'X': 'vanessa'}, {'X': 'patricia'}, {'X': 'susan'}, {'X': 'john'}, {'X': 'michael'}, {'X': 'michelle'}]), ] def test(program, solved_problems): @@ -75,29 +82,29 @@ def hint(program, solved_problems): # gender testing is redundant # this is not necessarily wrong, but worth mentioning anyway targets = [prolog.util.Token('NAME', 'male'), prolog.util.Token('NAME', 'female')] - pos = [(t.pos, t.pos + len(t.val)) for t in tokens if t in targets] - if pos: - # TODO: resolve how highlighting info is communicated - return [{'id': 'gender_is_irrelevant', 'highlight': pos}] + marks = [(t.pos, t.pos + len(t.val)) for t in tokens if t in targets] + if marks: + return [{'id': 'gender_is_irrelevant_markup', 'start': m[0], 'end': m[1]} for m in marks] + \ + [{'id': 'gender_is_irrelevant'}] # grandparent is a sign of complications # it's likely used instead of recursion targets = [prolog.util.Token('NAME', 'grandparent')] - pos = [(t.pos, t.pos + len(t.val)) for t in tokens if t in targets] - if pos: - # TODO: resolve how highlighting info is communicated - return [{'id': 'grandparent_used', 'highlight': pos}] + marks = [(t.pos, t.pos + len(t.val)) for t in tokens if t in targets] + if marks: + return [{'id': 'grandparent_used_markup', 'start': m[0], 'end': m[1]} for m in marks] + \ + [{'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_truth(engine_id, 'parent(Y, X), \+ descendant(X, Y)'): - return [{'id', 'base_case'}] + return [{'id': 'base_case'}] # descendant of oneself if prolog.engine.ask_truth(engine_id, 'descendant(X, X)'): - return [{'id', 'descendant_of_oneself'}] + return [{'id': 'descendant_of_oneself'}] # X does not necessarily need to be a parent if prolog.engine.ask_one(engine_id, @@ -109,7 +116,7 @@ def hint(program, solved_problems): if prolog.engine.ask_truth(engine_id, 'findall(_, descendant(william, X), L1), length(L1, 6), \ findall(_, descendant(X, william), L2), length(L2, 2)'): - return [{'id', 'wrong_direction'}] + return [{'id': 'wrong_direction'}] except socket.timeout as ex: pass diff --git a/prolog/problems/family_relations/descendant_2/sl.py b/prolog/problems/family_relations/descendant_2/sl.py index 5e81d26..5f4a3ca 100644 --- a/prolog/problems/family_relations/descendant_2/sl.py +++ b/prolog/problems/family_relations/descendant_2/sl.py @@ -14,31 +14,38 @@ description = '''\ plan = ['''\

Brez rekurzije ne bo šlo... kako lahko problem prevedem na (en korak) manjši problem?

-

-

Loni naj zbriše imena relacij (parent, ancestor) s te slike!

-''', '''\ -

+

Potomec od nekoga, ki je otrok od Y, je tudi potomec od Y.

''', '''\

Če je nek Z starš od X in je ta Z hkrati potomec od Y, potem je tudi X potomec od Y.

+''', '''\ +

Če je X potomec od Z, ki je otrok od Y, potem je X tudi potomec od Y.

'''] hint = { 'gender_is_irrelevant': '''\

Je spol res pomemben?

+''', + + 'gender_is_irrelevant_markup': '''\ +

Je to res potrebno?

''', 'grandparent_used': '''\

Rešitev z "grandparent" bo premalo splošna, poskusi nadomestiti to z rekurzijo. Skratka, poskusi prevesti na "manjši" problem, npr. potomec v enem koraku manj (en korak bližji potomec)...

+''', + + 'grandparent_used_markup': '''\ +

Bi se dalo rešiti brez tega?

''', 'base_case': '''\

Si pomislil na robni pogoj? Kaj je najbolj enostaven par (potomec, prednik)?

-

-''', +

+''', # TODO: morda ta hint naredim z "more": najprej tekst, ob kliku pa še slika... (sicer je preveč očitno) 'descendant_of_oneself': '''\

Kako je lahko nekdo potomec samega sebe?

@@ -51,12 +58,13 @@ Skratka, poskusi prevesti na "manjši" problem, npr. potomec v enem koraku manj 'wrong_direction': '''\

Si morda sprogramiral ravno obratno in zamenjal prednika s potomcem? X naj bo potomec od Y in ne obratno!

-''', +

+''', # TODO: Tim, kako bi lahko še query poslali med parametri v Hint dict? Je to predvideno? Tukaj bi recimo pasalo... 'interesting_tidbit': '''\

Zanimivost: nalogo bi lahko rešil tudi z uporabo rešitve za relacijo "ancestor". Samo obrni spremenljivki X in Y; če je X potomec od Y, potem je Y prednik od X.

-''', +''', # TODO: trigger za interesting tidbit } -- cgit v1.2.1