From 71772851de61a77598bd5ffc2e729a82d5da6416 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Mon, 14 Mar 2016 04:06:03 +0100 Subject: Hints for last_elem/2 updated. --- prolog/problems/lists/last_elem_2/common.py | 14 ++++++++++---- prolog/problems/lists/last_elem_2/sl.py | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'prolog/problems/lists') diff --git a/prolog/problems/lists/last_elem_2/common.py b/prolog/problems/lists/last_elem_2/common.py index 75cec75..9c44231 100644 --- a/prolog/problems/lists/last_elem_2/common.py +++ b/prolog/problems/lists/last_elem_2/common.py @@ -29,6 +29,7 @@ hint_type = { '[]_should_not_succeed': Hint('[]_should_not_succeed'), 'list_returned': Hint('list_returned'), 'clumsy_conc_use': Hint('clumsy_conc_use'), + 'unsuccessful_conc_use': Hint('unsuccessful_conc_use'), } test_cases = [ @@ -77,15 +78,20 @@ def hint(code, aux_code): # recursion is getting bigger and bigger - # succeeds when asked to return the last element of an empty list - if prolog.engine.ask_truthTO(engine_id, 'last_elem([], _)'): - return [{'id': '[]_should_not_succeed'}] - # using conc, but clumsily: conc(_, X, L) instead of conc(_, [X], L) if prolog.util.Token('NAME', 'conc') in tokens and \ prolog.engine.ask_truthTO(engine_id, 'last_elem([q,a,b,c], [q,a,b,c])'): return [{'id': 'clumsy_conc_use'}] + # general unsuccessful use of conc, but not specifically detected + # return general_conc hint, not to confuse/force the student into a non-conc solution + if prolog.util.Token('NAME', 'conc') in tokens: + return [{'id': 'unsuccessful_conc_use'}] + + # succeeds when asked to return the last element of an empty list + if prolog.engine.ask_truthTO(engine_id, 'last_elem([], _)'): + return [{'id': '[]_should_not_succeed'}] + # returns a list, not an element as required if prolog.engine.ask_truthTO(engine_id, 'last_elem([q], X), is_list(X)'): return [{'id': 'list_returned'}] diff --git a/prolog/problems/lists/last_elem_2/sl.py b/prolog/problems/lists/last_elem_2/sl.py index bcc33f8..7ab8ddc 100644 --- a/prolog/problems/lists/last_elem_2/sl.py +++ b/prolog/problems/lists/last_elem_2/sl.py @@ -49,6 +49,11 @@ implicitno že kar v argumentih predikata (glavi stavka).

'clumsy_conc_use': '''\

Uporabljaš conc/3? Zanimiva ideja. Ne pozabi, da mora drugi seznam, ki ga konkateniraš biti dolžine ena, če hočeš doseči to kar želiš. Torej vzorec oblike [X], kajne?

+''', + + 'unsuccessful_conc_use': '''\ +

Uporabljaš conc/3? Zanimiva ideja, da se rešiti tudi tako. Vendar boš moral še malo premisliti. +Ne pozabi, conc/3 ima tri argumente, vsi so seznami. Premisli, kakšen vzorec potrebuješ...

''', 'recursive_case': '''\ -- cgit v1.2.1