From 3cfb316886bafb00e1d12b7364892366497f0c16 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 20 Mar 2016 11:11:56 +0100 Subject: Prolog: add triggers for rev hints --- prolog/problems/lists_advanced/rev_2/common.py | 36 ++++++++++++++++++++++++++ prolog/problems/lists_advanced/rev_2/sl.py | 28 ++++++++++++++++++++ 2 files changed, 64 insertions(+) (limited to 'prolog') diff --git a/prolog/problems/lists_advanced/rev_2/common.py b/prolog/problems/lists_advanced/rev_2/common.py index d9becb6..ee8c9ac 100644 --- a/prolog/problems/lists_advanced/rev_2/common.py +++ b/prolog/problems/lists_advanced/rev_2/common.py @@ -27,6 +27,13 @@ hint_type = { 'base_case': Hint('base_case'), 'recursive_case': Hint('recursive_case'), 'timeout': Hint('timeout'), + 'invalid_insert_at_end': Hint('invalid_insert_at_end'), + 'base_case_at_len1': Hint('base_case_at_len1'), + 'arbitrary_base_case': Hint('arbitrary_base_case'), + 'forcing_result_onto_recursion': Hint('forcing_result_onto_recursion'), + 'using_other_solutions': Hint('using_other_solutions'), + 'insertion_at_beginning': Hint('insertion_at_beginning'), + 'conc_arg_not_list': Hint('conc_arg_not_list'), } test_cases = [ @@ -71,6 +78,35 @@ 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'}] + if prolog.engine.ask_truthTO(engine_id, 'rev([q], [q]), \+ rev([], [])'): + return [{'id': 'base_case_at_len1'}] + + if prolog.engine.ask_truthTO(engine_id, 'rev([], kokos(1))'): + return [{'id': 'arbitrary_base_case'}] + + if prolog.engine.ask_truthTO(engine_id, '''\ + \+ rev([yowza, brix, cob], R), + asserta(rev([brix, cob], [[cob, brix] | yowza])), + rev([yowza, brix, cob], [cob, brix]), + retract(rev([brix, cob], [[cob, brix] | yowza]))'''): + return [{'id': 'forcing_result_onto_recursion'}] + + if any(t.val in ('last', 'shiftleft', 'shiftright') for t in tokens): + return [{'id': 'using_other_solutions'}] + + if prolog.engine.ask_truthTO(engine_id, 'rev([qa, qb, qc, qd], [qa, qb, qc, qd])'): + return [{'id': 'insertion_at_beginning'}] + + if prolog.engine.ask_truthTO(engine_id, 'rev([a, b, c], [[[[] | c] | b] | a])'): + return [{'id': 'invalid_insert_at_end'}] + + if prolog.engine.ask_truthTO(engine_id, '''\ + \+ rev([yowza, brix, cob], R), + asserta(rev([brix, cob], [cob, brix])), + rev([yowza, brix, cob], [cob, brix | yowza]), + retract(rev([brix, cob], [cob, brix]))'''): + return [{'id': 'conc_arg_not_list'}] + # missing/failed base case if not prolog.engine.ask_truthTO(engine_id, 'rev([], [])'): return [{'id': 'base_case'}] diff --git a/prolog/problems/lists_advanced/rev_2/sl.py b/prolog/problems/lists_advanced/rev_2/sl.py index 666832d..806dc52 100644 --- a/prolog/problems/lists_advanced/rev_2/sl.py +++ b/prolog/problems/lists_advanced/rev_2/sl.py @@ -43,5 +43,33 @@ da je X hkrati starš in sestra od Y ali kaj podobno z 'timeout': '''\

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?

+''', + + 'base_case_at_len1': '''\ +

base_case_at_len1

+''', + + 'arbitrary_base_case': '''\ +

arbitrary_base_case

+''', + + 'forcing_result_onto_recursion': '''\ +

forcing_result_onto_recursion

+''', + + 'using_other_solutions': '''\ +

using_other_solutions

+''', + + 'insertion_at_beginning': '''\ +

insertion_at_beginning

+''', + + 'invalid_insert_at_end': '''\ +

invalid_insert_at_end

+''', + + 'conc_arg_not_list': '''\ +

conc_arg_not_list

''', } -- cgit v1.2.1