From 028ee21ff18c68f662a7dbf53ada4d22d486eb0f Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Fri, 9 Sep 2016 00:50:01 +0200 Subject: English translation for sublist/2 added. --- prolog/problems/lists_advanced/palindrome_1/en.py | 3 +- prolog/problems/lists_advanced/sublist_2/en.py | 53 ++++++++++++++++++++++- prolog/problems/lists_advanced/sublist_2/sl.py | 4 +- 3 files changed, 55 insertions(+), 5 deletions(-) (limited to 'prolog') diff --git a/prolog/problems/lists_advanced/palindrome_1/en.py b/prolog/problems/lists_advanced/palindrome_1/en.py index 27103d3..8471ae2 100644 --- a/prolog/problems/lists_advanced/palindrome_1/en.py +++ b/prolog/problems/lists_advanced/palindrome_1/en.py @@ -13,7 +13,8 @@ description = '''\ ''' plan = ['''\ -

A palindrome is a list (ok, a word) that reads the same from front or back. Like aibohphobia. ;)

+

A palindrome is a list (ok, a word) that reads the same from front or back. Like aibohphobia! +Was it a car or a cat I saw? ;)

''', '''\

As always we want to reduce the problem into a smaller one. Let's chop off the first and the last element of a list, and, if equal, proceed recursively.

diff --git a/prolog/problems/lists_advanced/sublist_2/en.py b/prolog/problems/lists_advanced/sublist_2/en.py index 67b50a4..33e59c5 100644 --- a/prolog/problems/lists_advanced/sublist_2/en.py +++ b/prolog/problems/lists_advanced/sublist_2/en.py @@ -2,7 +2,7 @@ name = 'sublist/2' slug = 'generate sublists of a list' description = '''\ -

sublist(L, SL): SL is a continuous sublist of the +

sublist(L, SL): SL is a continuous sublist of list L. Your program should return every possible sublist; each answer may be returned more than once.

@@ -16,4 +16,53 @@ answer may be returned more than once.

X = [3].
''' -hint = {} +plan = ['''\ +

First a reminder: we're looking for sublists, not subsets. The difference is that sublists contain a number of +consecutive elements of the original list.

+

Perhaps you should look for some pattern? And which predicate is ideal to search for patterns? +You already know that. ;)

+''', '''\ +

Of course, predicate conc/3 can be used to search for patterns in lists. Perhaps this time +we don't even need explicite recursion? Is that really possible in prolog? ;)

+''', '''\ +

So, what could the pattern be? Well, a part of the original list! Imagine that the original list is a tube +that you want to shorten -- a little bit from the left, a little bit from the right -- what's left is a sublist! +You chop off some elements from the front of the original list, and then you chop off some from the end.

+'''] + +hint = { + 'eq_instead_of_equ': '''\ +

The operator == is "stricter" than operator = in the sense that +for the latter it is enough to be able to make the two operands equal (unification). Perhaps by using = +you can make the predicate sublist/2 more general (e.g. able to work with output arguments becoming inputs).

+

Of course, you can also solve the exercise without explicit use of either of these two operators, just +remember that unification is implicitly performed with the predicate's arguments (head of clause).

+''', + + 'eq_instead_of_equ_markup': '''\ +

Perhaps the operator for unification (=) would be better?

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

Did you think of a base case?

+''', + + 'recursive_case': '''\ +

The base case is ok. However, what about the general recursive case?

+''', + + 'predicate_always_false': '''\ +

It seems your predicate is always "false". Did you give it the correct name, +or is it perhaps misspelled?

+

If the name is correct, check whether something else is misspelled, perhaps there is a full stop instead of +a comma or vice versa, or maybe you typed a variable name in lowercase?

+

It is, of course, also possible that your conditions are too restrictive, or even impossible to satisfy +(as would be, for example, the condition that N is equal to N + 1, +or something similarly impossible).

+''', + + 'timeout': '''\ +

Is there an infinite recursion at work here? How will it ever stop?

+

Or perhaps is there a missing, faulty, or simply incompatible (with the general recursive case) base case?

+''', +} diff --git a/prolog/problems/lists_advanced/sublist_2/sl.py b/prolog/problems/lists_advanced/sublist_2/sl.py index 4884665..b75aa0c 100644 --- a/prolog/problems/lists_advanced/sublist_2/sl.py +++ b/prolog/problems/lists_advanced/sublist_2/sl.py @@ -33,7 +33,7 @@ hint = { 'eq_instead_of_equ': '''\

Operator == je strožji od operatorja = v smislu, da je za slednjega dovolj, da elementa lahko naredi enaka (unifikacija). Morda z uporabo = narediš predikat -memb/2 delujoč tudi v kakšni drugi smeri.

+sublist/2 delujoč tudi v kakšni drugi smeri.

Seveda pa lahko nalogo rešiš brez obeh omenjenih operatorjev, spomni se, da lahko unifikacijo narediš implicitno že kar v argumentih predikata (glavi stavka).

''', @@ -56,7 +56,7 @@ Do katerega elementa najlažje prideš?

Če je ime pravilno, se morda splača preveriti tudi, če se nisi zatipkal kje drugje, je morda kakšna pika namesto vejice ali obratno, morda kakšna spremenljivka z malo začetnico?

Možno je seveda tudi, da so tvoji pogoji prestrogi ali celo nemogoči (kot bi bila npr. zahteva, -da je X hkrati starš in sestra od Y ali kaj podobno zlobnega).

+da je N enako kot N + 1 ali kaj podobno logično zlobnega).

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