From f193671b6ab09178e1dc1325f56844c22fa409b9 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 20 Mar 2016 10:53:25 +0100 Subject: Prolog: add triggers for shiftright hints --- .../problems/lists_advanced/shiftright_2/common.py | 30 ++++++++++++++++++++++ prolog/problems/lists_advanced/shiftright_2/sl.py | 15 +++++++++++ 2 files changed, 45 insertions(+) diff --git a/prolog/problems/lists_advanced/shiftright_2/common.py b/prolog/problems/lists_advanced/shiftright_2/common.py index 3df6621..b945440 100644 --- a/prolog/problems/lists_advanced/shiftright_2/common.py +++ b/prolog/problems/lists_advanced/shiftright_2/common.py @@ -23,6 +23,11 @@ hint_type = { 'eq_instead_of_equ': Hint('eq_instead_of_equ'), 'predicate_always_false': Hint('predicate_always_false'), 'timeout': Hint('timeout'), + 'conc_2nd_argument_not_1elem_list': Hint('conc_2nd_argument_not_1elem_list'), + 'arbitrary_result': Hint('arbitrary_result'), + 'shiftleftish_solution': Hint('shiftleftish_solution'), + 'last_used': Hint('last_used'), + 'final_hint': Hint('final_hint'), } test_cases = [ @@ -51,6 +56,9 @@ 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): + hints += [{'id': 'final_hint'}] + return n_correct, len(test_cases), hints def hint(code, aux_code): @@ -67,6 +75,28 @@ def hint(code, aux_code): return [{'id': 'eq_instead_of_equ_markup', 'start': m[0], 'end': m[1]} for m in marks] + \ [{'id': 'eq_instead_of_equ'}] + # second argument to conc is not first element in list + if prolog.engine.ask_truthTO(engine_id, + 'findall(L, shiftright([a, b, c], L), [[[a, b, c]], [[b, c], a], [[c], a, b], [[], a, b, c]])'): + return [{'id': 'conc_2nd_argument_not_1elem_list'}] + + # arbitrary result + if prolog.engine.ask_truthTO(engine_id, '''\ + shiftright([a, b, c], [yowza, brix, cob]) + ; + shiftright([a, b, yowza], [yowza | kokos(1)]) + ; + findall(L, shiftright([a, b, c], L), [[[a, b, c] | b], [[b, c] | r], [[c] | i], [[] | x]])'''): + return [{'id': 'arbitrary_result'}] + + # shiftleftish solution + if prolog.engine.ask_truthTO(engine_id, 'shiftright([a, b, c, yowza], [[b, c, yowza] | a])'): + return [{'id': 'shiftleftish_solution'}] + + # last/2 used + if any(t.val == 'last' for t in tokens): + return [{'id': 'last_used'}] + # target predicate seems to always be false if not prolog.engine.ask_truthTO(engine_id, 'shiftright(_, _)'): return [{'id': 'predicate_always_false'}] diff --git a/prolog/problems/lists_advanced/shiftright_2/sl.py b/prolog/problems/lists_advanced/shiftright_2/sl.py index 33f2dc7..3dfb637 100644 --- a/prolog/problems/lists_advanced/shiftright_2/sl.py +++ b/prolog/problems/lists_advanced/shiftright_2/sl.py @@ -33,4 +33,19 @@ da je X hkrati starš in sestra od Y ali kaj podobno z

Je morda na delu potencialno neskončna rekurzija? Kako se bo ustavila?

Morda pa je kriv tudi manjkajoč, neustrezen ali preprosto nekompatibilen (s splošnim primerom) robni pogoj?

''', + +'conc_2nd_argument_not_1elem_list': '''\ +

conc_2nd_argument_not_1elem_list

''', + +'arbitrary_result': '''\ +

arbitrary_result

''', + +'shiftleftish_solution': '''\ +

shiftleftish_solution

''', + +'last_used': '''\ +

last_used

''', + +'final_hint': '''\ +

final_hint

''', } -- cgit v1.2.1