From 4a01e895b521c75406270abd581cd3fbb09f2c08 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Thu, 8 Sep 2016 00:28:56 +0200 Subject: English translations for min/2 and max/2 added. --- prolog/problems/lists_advanced/min_2/en.py | 89 +++++++++++++++++++++++++++++- prolog/problems/lists_advanced/min_2/sl.py | 7 ++- 2 files changed, 90 insertions(+), 6 deletions(-) (limited to 'prolog/problems/lists_advanced/min_2') diff --git a/prolog/problems/lists_advanced/min_2/en.py b/prolog/problems/lists_advanced/min_2/en.py index a286cac..20677c6 100644 --- a/prolog/problems/lists_advanced/min_2/en.py +++ b/prolog/problems/lists_advanced/min_2/en.py @@ -1,8 +1,8 @@ name = 'min/2' -slug = 'find the smallest element' +slug = 'find the smallest element of a list' description = '''\ -

min(L, Min): Min is the smallest value in the list L.

+

min(L, Min): Min is the smallest value in list L.

 ?- min([5,4,1,6], M).
   M = 1.
@@ -10,4 +10,87 @@ description = '''\
   M = 2.
 
''' -hint = {} +plan = ['''\ +

As usual, try to reduce the problem to a smaller one. Say you already have the smallest element +of the tail...

+''', '''\ +

Compare the smallest element in the tail (list without head H) with the value of head H, +the smaller of the two wins and gets returned.

+''', '''\ +

If the given list L is composed of head H and tail T, and if we +assume that some MinT is the smallest element in T, and if it's also true that +the value of H is smaller than MinT, then H is the smallest element +in L. Or it is true that H is greater than MinT, and in this +case MinT is the smallest element in L.

+'''] + +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 min/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? What's the shortest list with an obvious smallest element?

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

+''', + + 'empty_list_base_case': '''\ +

You'll be hard pressed to find the smallest element of an empty list. What if you stop +the recursion a bit earlier this time?

+''', + + 'list_instead_of_elem_base_case': '''\ +

You should return an element, not a list!

+''', + + 'duplicates_not_covered': '''\ +

The list can contain duplicate elements. Did you think of that?

+''', + + 'args_not_instantiated': '''\ +

The error that prolog reported means that when it encountered an arithmetic operation, not all the +values were known.

+

Did you perhaps forget that conjunction has higher precedence that disjunction and that every prolog's +sentence (branch, rule) is independent in terms of the scope of the variables? This could be the problem. +Carefully inspect both blocks of code (before and after the semicolon) or both rules.

+''', + + 'unprotected_branch': '''\ +

It seems you didn't "protect" one of the (conditional) branches. Both branches (of the disjunction) typically +require a condition. Don't rely that if the execution reached the second branch that the first branch is false. +The relation between them is OR and not XOR. It's your job to make them mutually exclusive. Try the following +query and check all possible solutions and you'll notice the problem.

+

?- min([1,9,3,8,6], Min).

+''', + + 'one_branch_missing': '''\ +

Maybe you forgot one of the possibilities? The head can be either greater or smaller than +the smallest element in the tail.

+''', +} diff --git a/prolog/problems/lists_advanced/min_2/sl.py b/prolog/problems/lists_advanced/min_2/sl.py index bac4dc6..4a6975e 100644 --- a/prolog/problems/lists_advanced/min_2/sl.py +++ b/prolog/problems/lists_advanced/min_2/sl.py @@ -1,5 +1,5 @@ name = 'min/2' -slug = 'Poišči najmanjši element v danem seznamu' +slug = 'Poišči najmanjši element v seznamu' description = '''\

min(L, Min): Min je najmanjši element v seznamu L.

@@ -11,7 +11,8 @@ description = '''\ ''' plan = ['''\ -

Kot vedno, poskusi prevesti na manjši problem. Recimo, da že imaš najmanjši element v repu seznama...

+

Kot vedno, poskusi prevesti na manjši problem. Recimo, da že imaš najmanjši element v +repu seznama...

''', '''\

Najmanjši element v repu (seznamu brez glave H) primerjaj z vrednostjo glave H, tisti, ki je manjši zmaga in ga vrneš!

@@ -27,7 +28,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.

+min/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).

''', -- cgit v1.2.1 From 9e5d6dac0e32ecdce036041c878c290dc06599d9 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Wed, 21 Sep 2016 19:55:01 +0200 Subject: English translation for isort/2 added. --- prolog/problems/lists_advanced/min_2/en.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prolog/problems/lists_advanced/min_2') diff --git a/prolog/problems/lists_advanced/min_2/en.py b/prolog/problems/lists_advanced/min_2/en.py index 20677c6..4835d9d 100644 --- a/prolog/problems/lists_advanced/min_2/en.py +++ b/prolog/problems/lists_advanced/min_2/en.py @@ -46,7 +46,7 @@ remember that unification is implicitly performed with the predicate's arguments ''', 'predicate_always_false': '''\ -

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

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?

-- cgit v1.2.1