From d2264c60a2382d0aa00ec4cf8cc5d794213e2a2a Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Thu, 8 Sep 2016 21:17:16 +0200 Subject: English translation for palindrome/1 added. --- prolog/problems/lists_advanced/palindrome_1/en.py | 76 ++++++++++++++++++++++- prolog/problems/lists_advanced/palindrome_1/sl.py | 11 ++-- 2 files changed, 81 insertions(+), 6 deletions(-) (limited to 'prolog/problems/lists_advanced/palindrome_1') diff --git a/prolog/problems/lists_advanced/palindrome_1/en.py b/prolog/problems/lists_advanced/palindrome_1/en.py index bc6342b..27103d3 100644 --- a/prolog/problems/lists_advanced/palindrome_1/en.py +++ b/prolog/problems/lists_advanced/palindrome_1/en.py @@ -8,6 +8,80 @@ description = '''\ true. ?- palindrome([1,2,3]). false. +?- palindrome([a,b,b,a]). + true. ''' -hint = {} +plan = ['''\ +

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

+''', '''\ +

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.

+''', '''\ +

If head H of list L is equal to the list's last element, and if the remainder +(middle part) is a palindrome, then list L is also a palindrome.

+'''] + +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).

+

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? Which list represents the shortest possible palindrome?

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

+''', + + '[X,X]_instead_of_[]_base_case': '''\ +

Well, [X,X] is definitely a good base case. However, it doesn't cover one special case, +and that is an empty list. Of course, this is a matter of definition (taste even?), but please correct it +so that we all have solutions working in the same way.

+''', + + 'one_base_case_missing': '''\ +

Do you take two elements out with each recursive call? How does this end? Odd, even? ;)

+

Try the following two queries. One will work nicely, the other one won't. What's the difference?

+

?- palindrome([a,b,b,a]).

+

?- palindrome([l,e,v,e,l]).

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

Note that _ is not the same as [_]. The first pattern represents an arbitrary +variable (anything), the second a list with a single arbitrary element.

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

By using predicate last/2 it will be difficult to solve this exercise as it leaves the last +element in the original list.

''', + + 'final_hint_1': '''\ +

Interesting tidbit: do you know that you could have solved this exercise with just a single predicate call? +What happens with the palindrome if you... hmm, reverse it? ;)

+''', + + 'final_hint_2': '''\ +

You can make the solution even shorter! How can you get rid of the operator = (==) +or rather make it implicit?

+''', +} diff --git a/prolog/problems/lists_advanced/palindrome_1/sl.py b/prolog/problems/lists_advanced/palindrome_1/sl.py index 30a6bab..1e4e568 100644 --- a/prolog/problems/lists_advanced/palindrome_1/sl.py +++ b/prolog/problems/lists_advanced/palindrome_1/sl.py @@ -8,6 +8,8 @@ description = '''\ true. ?- palindrome([1,2,3]). false. +?- palindrome([a,b,b,a]). + true. ''' plan = ['''\ @@ -22,8 +24,7 @@ palindrom, potem je tudi celoten seznam L palindrom.

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.

+da elementa lahko naredi enaka (unifikacija).

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

''', @@ -50,8 +51,8 @@ da je N enako kot N + 1 ali kaj podobno logično zlobn ''', '[X,X]_instead_of_[]_base_case': '''\ -

Vsekakor je [X,X] povsem dober robni pogoj, a ne pokrije posebnega primera, ko je vhod kar prazen seznam. To je -seveda stvar definicije, a da bomo imeli vsi enake rešitve, prosim, popravi.

+

Vsekakor je [X,X] povsem dober robni pogoj, a ne pokrije posebnega primera, ko je vhod kar +prazen seznam. To je seveda stvar definicije, a da bomo imeli vsi enake rešitve, prosim, popravi.

''', 'one_base_case_missing': '''\ @@ -62,7 +63,7 @@ seveda stvar definicije, a da bomo imeli vsi enake rešitve, prosim, popravi.

Pazi _ ni enako kot [_]. Prvo predstavlja poljubno spremenljivko, drugo seznam +

Pazi, _ ni enako kot [_]. Prvo predstavlja poljubno spremenljivko, drugo seznam z enim poljubnim elementom.

''', -- cgit v1.2.1 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 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'prolog/problems/lists_advanced/palindrome_1') 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.

-- cgit v1.2.1