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). --- .../ancestor_2/Prolog_ancestor_01.svg | 356 ++++++++ .../ancestor_2/Prolog_ancestor_02.svg | 292 +++++++ .../ancestor_2/Prolog_ancestor_03.svg | 766 +++++++++++++++++ .../ancestor_2/Prolog_ancestor_04.svg | 940 +++++++++++++++++++++ .../problems/family_relations/ancestor_2/common.py | 37 +- prolog/problems/family_relations/ancestor_2/sl.py | 25 +- 6 files changed, 2390 insertions(+), 26 deletions(-) create mode 100644 prolog/problems/family_relations/ancestor_2/Prolog_ancestor_01.svg create mode 100644 prolog/problems/family_relations/ancestor_2/Prolog_ancestor_02.svg create mode 100644 prolog/problems/family_relations/ancestor_2/Prolog_ancestor_03.svg create mode 100644 prolog/problems/family_relations/ancestor_2/Prolog_ancestor_04.svg (limited to 'prolog/problems/family_relations/ancestor_2') diff --git a/prolog/problems/family_relations/ancestor_2/Prolog_ancestor_01.svg b/prolog/problems/family_relations/ancestor_2/Prolog_ancestor_01.svg new file mode 100644 index 0000000..2478b13 --- /dev/null +++ b/prolog/problems/family_relations/ancestor_2/Prolog_ancestor_01.svg @@ -0,0 +1,356 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prolog/problems/family_relations/ancestor_2/Prolog_ancestor_02.svg b/prolog/problems/family_relations/ancestor_2/Prolog_ancestor_02.svg new file mode 100644 index 0000000..8d911be --- /dev/null +++ b/prolog/problems/family_relations/ancestor_2/Prolog_ancestor_02.svg @@ -0,0 +1,292 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prolog/problems/family_relations/ancestor_2/Prolog_ancestor_03.svg b/prolog/problems/family_relations/ancestor_2/Prolog_ancestor_03.svg new file mode 100644 index 0000000..08bb4c7 --- /dev/null +++ b/prolog/problems/family_relations/ancestor_2/Prolog_ancestor_03.svg @@ -0,0 +1,766 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prolog/problems/family_relations/ancestor_2/Prolog_ancestor_04.svg b/prolog/problems/family_relations/ancestor_2/Prolog_ancestor_04.svg new file mode 100644 index 0000000..8118e75 --- /dev/null +++ b/prolog/problems/family_relations/ancestor_2/Prolog_ancestor_04.svg @@ -0,0 +1,940 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prolog/problems/family_relations/ancestor_2/common.py b/prolog/problems/family_relations/ancestor_2/common.py index 7249ed8..94b7e68 100644 --- a/prolog/problems/family_relations/ancestor_2/common.py +++ b/prolog/problems/family_relations/ancestor_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 = 100 @@ -21,8 +21,10 @@ ancestor(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'), 'ancestor_to_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 + ('ancestor(ana, X)', + [{'X': 'aleksander'}, {'X': 'luana'}, {'X': 'daniela'}]), + ('ancestor(morty, X)', + [{'X': 'jerry'}, {'X': 'anna'}]), + ('ancestor(X, susan)', + [{'X': 'vanessa'}, {'X': 'patrick'}, {'X': 'tina'}, {'X': 'thomas'}, {'X': 'william'}]), ] 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(X, Y), \+ ancestor(X, Y)'): - return [{'id', 'base_case'}] + return [{'id': 'base_case'}] # ancestor to oneself if prolog.engine.ask_truth(engine_id, 'ancestor(X, X)'): - return [{'id', 'ancestor_to_oneself'}] + return [{'id': 'ancestor_to_oneself'}] # Y does not necessarily need to be a parent if prolog.engine.ask_one(engine_id, @@ -109,14 +116,14 @@ def hint(program, solved_problems): if prolog.engine.ask_truth(engine_id, 'findall(_, ancestor(william, X), L1), length(L1, 2), \ findall(_, ancestor(X, william), L2), length(L2, 6)'): - return [{'id', 'wrong_direction'}] + return [{'id': 'wrong_direction'}] except socket.timeout as ex: - pass + return [{'id': 'base_case'}] finally: if engine_id: prolog.engine.destroy(engine_id) - return None + return [] diff --git a/prolog/problems/family_relations/ancestor_2/sl.py b/prolog/problems/family_relations/ancestor_2/sl.py index d74ccc5..b0fae7c 100644 --- a/prolog/problems/family_relations/ancestor_2/sl.py +++ b/prolog/problems/family_relations/ancestor_2/sl.py @@ -14,31 +14,38 @@ description = '''\ plan = ['''\

Sedaj pa bo potrebna rekurzija... kako lahko problem prevedem na (en korak) manjši problem?

-

-

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

-''', '''\ -

+

Starš od nekoga, ki je prednik od Y, je tudi prednik od Y.

''', '''\

Če je X starš od nekega Z in je ta Z prednik od Y, potem je X tudi prednik od Y.

+''', '''\ +

Če je X starš od Z, ki je prednik od Y, potem je X tudi prednik 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. prednik v enem koraku manj (en korak bližji prednik)...

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

Bi se dalo rešiti brez tega?

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

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

-

-''', +

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

Kako je lahko nekdo prednik samemu sebi?

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

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

+

''', - -# 'interesting_tidbit': '''\ -#

Zanimivost: nalogo bi lahko rešil tudi z uporabo rešitve za relacijo "sister". -# Teta je namreč sestra od starša od Y.

-# ''', } -- cgit v1.2.1