From a4e8456ab5f14a34cb2f79c0946c439a976041f8 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Mon, 14 Mar 2016 03:44:53 +0100 Subject: Hints for last_elem/2 added. --- prolog/problems/lists/last_elem_2/common.py | 17 +++++++++++++++-- prolog/problems/lists/last_elem_2/sl.py | 13 +++++++++++++ 2 files changed, 28 insertions(+), 2 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 8c08d61..75cec75 100644 --- a/prolog/problems/lists/last_elem_2/common.py +++ b/prolog/problems/lists/last_elem_2/common.py @@ -26,6 +26,9 @@ hint_type = { 'recursive_case': Hint('recursive_case'), 'timeout': Hint('timeout'), 'final_hint': Hint('final_hint'), + '[]_should_not_succeed': Hint('[]_should_not_succeed'), + 'list_returned': Hint('list_returned'), + 'clumsy_conc_use': Hint('clumsy_conc_use'), } test_cases = [ @@ -74,6 +77,18 @@ 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'}] + + # 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'}] # missing/failed base case if not prolog.engine.ask_truthTO(engine_id, 'last_elem([qQ], qQ)'): @@ -89,8 +104,6 @@ def hint(code, aux_code): if not prolog.engine.ask_truth(engine_id, 'last_elem([qa,qb,qQ,qc], qc)'): return [{'id': 'recursive_case'}] - # TODO: Tim, can we include 'fail'-used as a general hint? - except socket.timeout as ex: return [{'id': 'timeout'}] diff --git a/prolog/problems/lists/last_elem_2/sl.py b/prolog/problems/lists/last_elem_2/sl.py index c0d8082..bcc33f8 100644 --- a/prolog/problems/lists/last_elem_2/sl.py +++ b/prolog/problems/lists/last_elem_2/sl.py @@ -36,6 +36,19 @@ implicitno že kar v argumentih predikata (glavi stavka).

'base_case': '''\

Si pomislil na robni pogoj? Kaj je najbolj enostaven primer? Kaj, če ima seznam samo en element?

+''', + + '[]_should_not_succeed': '''\ +

Kako si lahko uspešno našel zadnji element v praznem seznamu? Verjetno potrebuješ drugačen robni pogoj.

+''', + + 'list_returned': '''\ +

Vračaš seznam namesto elementa.

+''', + + '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?

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