From ca743bffb497dea794950bf2bbda45e3bb4c936b Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Sat, 27 Aug 2016 03:31:18 +0200 Subject: English translation for conc/3 added. --- prolog/problems/lists/conc_3/en.py | 112 ++++++++++++++++++++++++++++- prolog/problems/lists/conc_3/sl.py | 10 +-- prolog/problems/lists_advanced/rev_2/en.py | 4 +- 3 files changed, 118 insertions(+), 8 deletions(-) diff --git a/prolog/problems/lists/conc_3/en.py b/prolog/problems/lists/conc_3/en.py index e25ae32..2e74e5e 100644 --- a/prolog/problems/lists/conc_3/en.py +++ b/prolog/problems/lists/conc_3/en.py @@ -10,4 +10,114 @@ description = '''\ X = [1,2,3]. ''' -hint = {} +plan = ['''\ +

+''', '''\ +

Let's start with an easy question. What do I get if I concatenate an empty list and a list L2?

+''', '''\ +

Now, assume that the first list has exactly one element. Let's temporarily take it out which leaves us +with an empty list. But wait! Isn't this situation now similar to the one we dealt with before? Of course, we just +reduced the problem into a smaller one (by one element smaller). Let recursion solve this smaller problem. Just don't +forget to expand the recursion's result with the element you have taken out at the beginning...

+''', '''\ +

Declarative/logic reasoning: Assume the first list L1 has head H and tail +T. If the recursive result of concatenating T and L2 is some list +L3, and if we add element H at the beginning of list L3, what do we get? +A concatenation of L1 and L2!

+'''] + +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 rev/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 is the simplest possible case? +What's the answer if, for example, the first list is empty? (Just the first list should be empty, +the second one can be arbitrary.)

+''', + + 'base_case_arbitrary': '''\ +

How can the result of concatenating two lists be an arbitrary list (a variable without an assigned value)?

+

If your base case is similar to conc([], L, _), +then you should rethink it: what is the result of the concatenation, what do you return as the result? +The base case always fully specifies the result, usually there are no unknowns (_ +or variables without assigned values) in what is being returned as the result.

+''', + + '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 an empty list [] is equal to a list with +exactly three elements [A,B,C], +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? +Are you maybe reducing the first list, but your base case stops with an empty second list (or vice versa)?

+''', + + 'second_list_iteration': '''\ +

It seems you're processing (reducing) the second list. The mechanism at work is correct, however, +the final ordering of the elements is not. It's better to process the first list in this way and +leave the second one as is.

+

There's another reason to process the first list: in this way the solution of this essential exercise +will be the same for everyone, and we'll be able to use conc/3 in a standardised way. This +will be very important later on.

+''', + + 'insertion_into_second_list': ''' +

Is your recursive call of the form conc(T, [H|L2], ...)? +Don't insert the first list's head into the second list as this will result in the wrong ordering +of the elements. Let the recursion alone take care of concatenating the first list's tail +T with the second list L2, and then, when returning the complete result, +add the first list's head H into its proper place.

+''', + + 'two_heads': '''\ +

Do you really need two list heads? Are you trying to reduce both lists? This is not a good idea, it is +difficult to solve the exercise in this way. Rather simply reduce the first list only, and leave the +other list as is.

+''', + + 'two_heads_markup': '''\ +

Do you really need two list heads?

+''', + + 'forcing_result_onto_recursion': ''' +

Don't force the result onto recursion, don't tell it what it should return. Just assume it will do its job. +If this assumption is correct, then the rule will work for a larger case.

+

Is your recursive call of the form conc(T, L2, [H|...])? This forces the recursive call to +return the head at the start of the concatenated list. But it doesn't know of this head, because you just +took it away! Inserting the head into the result, returned by the recursive call, is your job. To put it shortly, +insert H outside of the recursive call.

+''', + + 'final_hint': '''\ +

Predicate conc/3 will be useful for much more than just concatenating two lists. +Among other things it can be used "in the other direction" -- for dividing a list into two parts. Try the +following queries:

+

?- conc(L1, L2, [a,b,c,d]).

+

?- conc([X,Y], L2, [a,b,c,d,e,f]).

+

Did you notice that the second query returned the first two elements from the list [a,b,c,d,e,f]?

+

Furthermore, conc/3 is useful to search for patterns in a list, e.g.:

+

?- conc(_, [X,X|_], [a,b,c,c,d,e,f,f,g,h,h]).

+

Right, this query finds all possibilities where two identical elements appear one after the other in a list +(pattern X,X). Basically the query said that "there are some elements (possibly zero) in front, then follow two +identical elements, and then again some elements (possibly zero) at the end."

+

There are many other usages of conc/3, you will discover them along the way.

+''', +} diff --git a/prolog/problems/lists/conc_3/sl.py b/prolog/problems/lists/conc_3/sl.py index be2590e..5b0a639 100644 --- a/prolog/problems/lists/conc_3/sl.py +++ b/prolog/problems/lists/conc_3/sl.py @@ -92,8 +92,8 @@ res težko prišel do pravilne rešitve. Raje zmanjšuj samo prvi seznam in pust 'forcing_result_onto_recursion': '''

Ne vsiljuj rekurziji kaj naj vrne, prepusti se ji. To je tisti del, ko narediš predpostavko, če je ta izpolnjena, potem bo tvoje pravilo delovalo za večji primer.

-

Je tvoj rekurzivni klic oblike conc(T, L2 [H|...])? S tem vsiljuješ rekurziji -da mora vrniti tudi glavo, ki si jo prej že dal začasno stran. Glavo moraš na koncu na primerno mesto +

Je tvoj rekurzivni klic oblike conc(T, L2, [H|...])? S tem vsiljuješ rekurziji +da mora vrniti tudi glavo, ki si jo prej že dal začasno stran. Glavo moraš na koncu na primerno mesto vstaviti ti. Skratka, glavo H dodaj izven rekurzivnega klica.

''', @@ -105,9 +105,9 @@ Med drugim je uporaben "v obratni smeri" za delitev seznama na dva dela, poskusi

Si opazil, da je drugo vprašanje v bistvu vrnilo prva dva elementa iz seznama [a,b,c,d,e,f]?

Nadalje je conc/3 uporaben za iskanje vzorcev v seznamu, npr. takole:

?- conc(_, [X,X|_], [a,b,c,c,d,e,f,f,g,h,h]).

-

Tako je, to vprašanje najde vse možnosti, kjer se dva elementa ponovita drug za drugim v seznamu (vzorec X,X). +

Tako je, to vprašanje najde vse možnosti, kjer se dva enaka elementa ponovita drug za drugim v seznamu (vzorec X,X). V bistvu smo rekli "nekaj poljubnih elementov (lahko tudi nič) je spredaj, potem sta dva enaka, potem pa spet nekaj -poljubnih elementov (lahko nič) zadaj." -Še veliko drugih koristi bo od conc/3, jih boš že še sproti spoznal.

+poljubnih elementov (lahko nič) zadaj."

+

Še veliko drugih koristi bo od conc/3, jih boš že še sproti spoznal.

''', } diff --git a/prolog/problems/lists_advanced/rev_2/en.py b/prolog/problems/lists_advanced/rev_2/en.py index 3b85a74..dbb08a2 100644 --- a/prolog/problems/lists_advanced/rev_2/en.py +++ b/prolog/problems/lists_advanced/rev_2/en.py @@ -25,7 +25,7 @@ and if I assume the recursion reverses tail T into reversed tail The operator == is "stricter" than operator = in the sense that -for the latter it is enough to be able to make two elements equal (unification). Perhaps by using = +for the latter it is enough to be able to make the two operands equal (unification). Perhaps by using = you can make the predicate rev/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).

@@ -72,7 +72,7 @@ an assigned value)!

Don't force the result onto recursion, don't tell it what it should return. Just assume it will do its job. If this assumption is correct, then the rule will work for a larger case.

Is your recursive call of the form rev(T, [RevTail|H])? This forces the recursive call to -return the head at the end of the list. But it doesn't know of this head, because you just +return the head at the end of the list. But it doesn't know of this head, because you just took it away! Inserting the head into the result, returned by the recursive call, is your job. To put it shortly, insert H outside of the recursive call.

''', -- cgit v1.2.1 From 918513a870273ab70e6ea60ab25344b77a44fec3 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Sun, 28 Aug 2016 23:07:01 +0200 Subject: English translation for memb/2 added. --- prolog/problems/lists/conc_3/en.py | 2 +- prolog/problems/lists/memb_2/en.py | 68 +++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/prolog/problems/lists/conc_3/en.py b/prolog/problems/lists/conc_3/en.py index 2e74e5e..c384222 100644 --- a/prolog/problems/lists/conc_3/en.py +++ b/prolog/problems/lists/conc_3/en.py @@ -30,7 +30,7 @@ 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 rev/2 more general (e.g. able to work with output arguments becoming inputs).

+you can make the predicate conc/3 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).

''', diff --git a/prolog/problems/lists/memb_2/en.py b/prolog/problems/lists/memb_2/en.py index ae62825..681c18a 100644 --- a/prolog/problems/lists/memb_2/en.py +++ b/prolog/problems/lists/memb_2/en.py @@ -12,4 +12,70 @@ description = '''\ X = 1. ''' -hint = {} +plan = ['''\ +

Where can we find the searched for element X? Remember that the list has two parts: the head and +the tail. Therefore, there are two possibilies! ;)

+''', '''\ +

+

In prolog we can understand a list like a queue of people waiting for a bus. The driver only sees +the first person in the queue, the others are hidden in the list's tail. So the element X +can either be at the start of the queue or...

+''', '''\ +

It's easy to look at ("search for") the head of the list. But how do we search the tail? Simply, +we remove the first element and repeat the search with the smaller list (tail). If [H|T] +is our whole list, then T is this same list without the first element. +Since the new list (tail) is smaller, we reduced the problem and thus facilitated the use of recursion.

+'''] + +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 memb/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 is the simplest possible case if the element is present in the list? +Which element in the list is the easiest to access?

+''', + + '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 an empty list [] is equal to a list with +exactly three elements [A,B,C], +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?

+''', + + 'final_hint': '''\ +

Predicate memb/2 is useful for much more than just checking whether a list contains +a given element or not. Actually, most of the time, it's used in "a different direction" as +"return some element X from list L". In fact you've just written yourself +a generator of elements from the list.

+

Try the following query:

+

?- memb(Coin, [1,2,5,10,20,50,100,200]).

+

or this one:

+

?- memb(Operator, [+, -, *, /]).

+

Can you form a query to ask prolog how do we get a sum of 30 cents with exactly three coins? +The operator =:= is used to check for arithmetic equality. How many solutions are there? ;)

+''', +} -- cgit v1.2.1 From 464f5fd3eebfc30fa487eebb29b24727b98276f1 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Mon, 29 Aug 2016 00:45:09 +0200 Subject: English translation for insert/3 added. --- prolog/problems/lists/insert_3/en.py | 83 +++++++++++++++++++++++++++++++++++- prolog/problems/lists/insert_3/sl.py | 2 +- 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/prolog/problems/lists/insert_3/en.py b/prolog/problems/lists/insert_3/en.py index 5553445..0de098b 100644 --- a/prolog/problems/lists/insert_3/en.py +++ b/prolog/problems/lists/insert_3/en.py @@ -10,4 +10,85 @@ description = '''\ L = [2,3,1]. ''' -hint = {} +plan = [''' +

+

Where in the list can we insert a new element X? Remember that a list has two parts: head and tail. +That means there are two possibilies. That's right, only two -- but in the tail we can again insert either as its +new head or into the tail of the tail. And so on. Recursion to the rescue!

+''', '''\ +

What is the simplest option? Insert at the beginning!

+''', '''\ +

How do I insert into the list's tail? Just divide the list into its head and tail, recursively (as +the problem is one element smaller now) insert into the tail, and at the end don't forget about the +head previously taken away.

+''', '''\ +

Recursive step: if we assume NewTail is the tail with already inserted element X, +then [H|NewTail] is the whole list with the element X inserted.

+'''] + +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 insert/3 more general (e.g. able to work with output arguments becoming inputs). +This might come in handy later on!

+

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? In which place in the list is it the easiest to insert a new 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 an empty list [] is equal to a list with +exactly three elements [A,B,C], +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?

+''', + + 'ins_results_in_empty_list': '''\ +

How can the result of the insertion be an empty list?

+

If that is your base case, rethink it! What is the result of the insertion?

+''', + + 'ins_results_in_arbitrary_result': '''\ +

How can the result of the insertion be an arbitrary list or an unassigned variable?

+

If that is your base case, rethink it! What is the result of the insertion?

+''', + + 'lost_heads': '''\ +

+

The element has been successfully inserted, but all the others before it are lost, right? +Did you forget to put the head back at the front of the list after returning from recursion?

+

Try asking prolog the following query and check all the solutions:

+

?- insert(q, [a,b,c,d], L).

+''', + + 'leading_heads_all_x': '''\ +

+

Did you forget (copy/paste?) and used [X|T] instead of the more general [H|T] +in the recursive case?

+

Of the following two queries one works and the other doesn't.

+

?- insert(d, [d,d,d,d,e,f,g], L).

+

?- insert(d, [a,b,c,d,e,f,g], L).

+''', +} diff --git a/prolog/problems/lists/insert_3/sl.py b/prolog/problems/lists/insert_3/sl.py index 17efb5b..7f62f7e 100644 --- a/prolog/problems/lists/insert_3/sl.py +++ b/prolog/problems/lists/insert_3/sl.py @@ -74,7 +74,7 @@ da je X hkrati starš in sestra od Y ali kaj podobno z

Element je vstavljen, ampak vsi pred njim so se pa izgubili, kajne? Si pozabil dati glavo nazaj na začetek seznama, ko se vračaš iz rekurzije?

-

Poskusi postaviti naslednje vprašanje prologu in preglej vse rešitve:

+

Poskusi postaviti naslednje vprašanje prologu in preglej vse rešitve:

?- insert(q, [a,b,c,d], L).

''', -- cgit v1.2.1 From 185990bb4435b23e50464125ecaf84f8aeae766d Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Mon, 29 Aug 2016 19:11:18 +0200 Subject: English translation for del/3 added. --- prolog/problems/lists/del_3/en.py | 93 +++++++++++++++++++++++++++++++++++- prolog/problems/lists/del_3/sl.py | 2 +- prolog/problems/lists/insert_3/en.py | 4 +- 3 files changed, 94 insertions(+), 5 deletions(-) diff --git a/prolog/problems/lists/del_3/en.py b/prolog/problems/lists/del_3/en.py index 99f87ca..d6e1e30 100644 --- a/prolog/problems/lists/del_3/en.py +++ b/prolog/problems/lists/del_3/en.py @@ -1,5 +1,5 @@ name = 'del/3' -slug = 'delete an element from list' +slug = 'delete element from list' description = '''\

del(X, L1, L2): the list L2 is obtained from L1 by deleting element X.

@@ -15,4 +15,93 @@ description = '''\ X = 3, L = [1,2]. ''' -hint = {} +plan = [''' +

+ + +

+

This exercise is very similar to the exercise memb/2, except that this time we also delete +the element we are looking for. Where in the list can element X be hiding? +Remember that a list has two parts: head and tail. Therefore there are two possibilies!

+''', '''\ +

What is the simplest option? Perhaps deleting the first element?

+''', '''\ +

How do I delete from the list's tail? Just divide the list into its head and tail, recursively (as +the problem is one element smaller now) delete from the tail, and at the end don't forget about the +head previously taken away.

+''', '''\ +

Recursive step: if we assume NewTail is the tail with element X already deleted, +then [H|NewTail] is the whole list with element X deleted.

+'''] + +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 del/3 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? Where in the list is it the easiest to delete an 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 an empty list [] is equal to a list with +exactly three elements [A,B,C], +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?

+''', + + 'del_from_empty_list_success': '''\ +

You can't delete an element from an empty list!

+

If I delete an element from an empty list, this doesn't result in an empty list or anything else, but it +simply shouldn't succeed. You don't even have to include a rule for this as prolog by default acts like that. +You know how prolog loves to say "no"! :)

+

If that is your base case, rethink it! Where in the list is it the easiest to delete an element?

+''', + + 'lost_heads': '''\ +

+

The element has been successfully deleted, but all the others before it got deleted too, right? +Did you forget to put the head back at the front of the list after returning from recursion?

+

Try asking the following query:

+

?- del(d, [a,b,c,d,e,f,g], L).

+''', + + 'leading_heads_all_x': '''\ +

+

Did you forget (copy/paste?) and used [X|T] instead of the more general [H|T] +in the recursive case?

+

Of the following two queries one works and the other doesn't.

+

?- del(d, [d,d,d,d,e,f,g], L).

+

?- del(d, [a,b,c,d,e,f,g], L).

+''', + + 'final_hint': '''\ +

Interesting tidbit. Inserting and deleting an element into/from the list are opposite operations. +Just by playing around with the arguments you can solve del/3 using insert/3.

+

Logically the following holds: deleting element X from list BigList resulting +in list SmallList is the same as inserting element X +into list SmallList to get list BigList as a result. ;)

+''', +} diff --git a/prolog/problems/lists/del_3/sl.py b/prolog/problems/lists/del_3/sl.py index feee5e4..17df017 100644 --- a/prolog/problems/lists/del_3/sl.py +++ b/prolog/problems/lists/del_3/sl.py @@ -97,7 +97,7 @@ Si pozabil dati glavo nazaj na začetek seznama, ko se vračaš iz rekurzije?

Zanimivost: operaciji vstavljanja in brisanja iz seznama sta si ravno nasprotni. Če se malce poigraš z argumenti, lahko del/3 rešiš kar z insert/3.

Logično velja naslednje: če zbrišem X iz seznama BigList in dobim kot rezultat -seznam SmallList je isto kot če vstavim X v seznam SmallList in dobim +seznam SmallList je isto kot če vstavim X v seznam SmallList in dobim kot rezultat seznam BigList. ;)

''', } diff --git a/prolog/problems/lists/insert_3/en.py b/prolog/problems/lists/insert_3/en.py index 0de098b..d246932 100644 --- a/prolog/problems/lists/insert_3/en.py +++ b/prolog/problems/lists/insert_3/en.py @@ -23,7 +23,7 @@ the problem is one element smaller now) insert into the tail, and at the end don head previously taken away.

''', '''\

Recursive step: if we assume NewTail is the tail with already inserted element X, -then [H|NewTail] is the whole list with the element X inserted.

+then [H|NewTail] is the whole list with element X inserted.

'''] hint = { @@ -79,7 +79,7 @@ or something similarly impossible).

The element has been successfully inserted, but all the others before it are lost, right? Did you forget to put the head back at the front of the list after returning from recursion?

-

Try asking prolog the following query and check all the solutions:

+

Try asking the following query and check all the solutions:

?- insert(q, [a,b,c,d], L).

''', -- cgit v1.2.1 From ac398acf224fbb6b8d5cc201bd5d924c33c9ba51 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Mon, 29 Aug 2016 20:44:27 +0200 Subject: English translation for dup/2 added. --- prolog/problems/lists/dup_2/en.py | 75 ++++++++++++++++++++++++++++++++++++++- prolog/problems/lists/dup_2/sl.py | 2 +- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/prolog/problems/lists/dup_2/en.py b/prolog/problems/lists/dup_2/en.py index 3639683..e944f74 100644 --- a/prolog/problems/lists/dup_2/en.py +++ b/prolog/problems/lists/dup_2/en.py @@ -10,4 +10,77 @@ description = '''\ X = [1,1,2,2,3,3]. ''' -hint = {} +plan = [''' +

+

This is an exercise in classic recursion. Let's be brave and assume that we already have +a duplicated tail of the list. Then all we need to do is to duplicate the head (H becomes H, H) and +add this at the start of the duplicated tail.

+''', '''\ +

A base case must be elementary, right? What if the list doesn't contain any elements at all, +what is the result in this case?

+''', '''\ +

If we have a duplicated tail DT and put two heads [H, H] in front of it, +then that is exactly the duplicated list.

+

And how do we get the duplicated tail? Since the tail is smaller than the whole list, +we can use recursion on it!

+'''] + +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 dup/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_missing_[]': '''\ +

Your base case makes perfect sense, but it doesn't work for a very specific case: an empty list. +Tweak it a little bit. However, don't write two base cases, because that will result in a new problem: +the (albeit correct) solutions will all be repeated twice.

+''', + + 'base_case_arbitrary': '''\ +

How can the result of duplicating an empty list be an arbitrary list or an unassigned variable? +As the mathematicians would say: "Two times zero is zero and not just anything!"

+

If your base case is dup([], _)., rethink it! What is the result of +duplicating the elements of an empty list?

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

Did you think of a base case? Which list is the easiest to "duplicate"?

+''', + + '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 an empty list [] is equal to a list with +exactly three elements [A,B,C], +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?

+''', + + 'forcing_result_onto_recursion': ''' +

Don't force the result onto recursion, don't tell it what it should return. Just assume it will do its job. +If this assumption is correct, then the rule will work for a larger case.

+

Is your recursive call of the form dup(T, [H,H|...])? This forces the recursive call to +return the duplicated head at the start of the list. But it doesn't know of this head, because you just +took it away! Adding the duplicated head to the result, returned by the recursive call, is your job. +To put it shortly, add the duplicated H outside of the recursive call.

+''', +} diff --git a/prolog/problems/lists/dup_2/sl.py b/prolog/problems/lists/dup_2/sl.py index 0358726..b1492c5 100644 --- a/prolog/problems/lists/dup_2/sl.py +++ b/prolog/problems/lists/dup_2/sl.py @@ -71,7 +71,7 @@ da je X hkrati starš in sestra od Y ali kaj podobno z

Ne vsiljuj rekurziji kaj naj vrne, prepusti se ji. To je tisti del, ko narediš predpostavko, če je ta izpolnjena, potem bo tvoje pravilo delovalo za večji primer.

Je tvoj rekurzivni klic oblike dup(T, [H,H|...])? S tem vsiljuješ rekurziji -da mora vrniti tudi podvojeno glavo. To moraš narediti ti z (obdelanim) rezultatom, ki ga rezurzija vrne. +da mora vrniti tudi podvojeno glavo. To moraš narediti ti z (obdelanim) rezultatom, ki ga rezurzija vrne. Skratka, [H,H] dodaj izven rekurzivnega klica.

''', } -- cgit v1.2.1 From 0331b2ff089f33a33f66470cec305ff08f829a30 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Tue, 30 Aug 2016 02:33:37 +0200 Subject: English translation for last_elem/2 added. --- prolog/problems/lists/last_elem_2/en.py | 84 ++++++++++++++++++++++++++++++++- prolog/problems/lists/last_elem_2/sl.py | 2 +- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/prolog/problems/lists/last_elem_2/en.py b/prolog/problems/lists/last_elem_2/en.py index 93c7c05..5eec3b8 100644 --- a/prolog/problems/lists/last_elem_2/en.py +++ b/prolog/problems/lists/last_elem_2/en.py @@ -10,4 +10,86 @@ description = '''\ X = 1. ''' -hint = {} +plan = ['''\ +

It's easy to access the first element in a list, but to get to the last element one needs to +recursively go through the whole list.

+''', '''\ +

The list can be divided into its head and tail, and the search can proceed with the tail. +The problem is now smaller (the tail is shorter than the whole list), so we can use recursion.

+''', '''\ +

If X is the last element of tail T, then X is also +the last element of the whole list that looks like [H|T].

+'''] + +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 last_elem/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 simplest possible case? What if the list contains only one element?

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

How did you succeed to find a last element in an empty list? You likely need a different base case.

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

You are returning a list instead of an element.

+''', + + 'clumsy_conc_use': '''\ +

Are you using conc/3? An interesting idea. Don't forget that the second list you're +concatenating must be of length one if you want to achieve the desired effect. +So a pattern of the form [X], right?

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

Are you using conc/3? An interesting idea; it is possible to solve in this way. +However, a bit of tweaking is still needed. Don't forget that conc/3 has three arguments, +and all three are lists. Think about what kind of a pattern do you need...

+''', + + '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 an empty list [] is equal to a list with +exactly three elements [A,B,C], +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?

+''', + + 'final_hint': '''\ +

Interesting fact: predicate conc/3 can be used to search for patterns in lists. The last +element in a list is also a kind of pattern. What happens if we concatenate an arbitrary list _ +and a list of length one (in this order)? A list of length one is of course written as +[Element].

+

Try asking the following query:

+

?- conc(_, [Element], [a,b,c,d,e,f,q]).

+

So, can you now fetch the list's last element using conc/3? This will be very useful in +further exercises. On the other hand, of course, accessing the last element of a list is still quite +expensive, it's done in O(n) time. Therefore, if it's not important which element of a list is to be used, +or where in a list a new element is to be added, always work with the head.

+

And what does this query do? ;)

+

?- conc([a,b,c], [q], L).

+''', +} diff --git a/prolog/problems/lists/last_elem_2/sl.py b/prolog/problems/lists/last_elem_2/sl.py index afba57a..961963c 100644 --- a/prolog/problems/lists/last_elem_2/sl.py +++ b/prolog/problems/lists/last_elem_2/sl.py @@ -47,7 +47,7 @@ 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?

+biti dolžine ena, če hočeš doseči to kar želiš. Torej vzorec oblike [X], kajne?

''', 'unsuccessful_conc_use': '''\ -- cgit v1.2.1 From ca2741f8d02d88288dfd1127c0faa9709ab83e6e Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Wed, 31 Aug 2016 03:08:54 +0200 Subject: English translation for permute/2 added. --- prolog/problems/lists/permute_2/en.py | 78 ++++++++++++++++++++++++++++++++++- prolog/problems/lists/permute_2/sl.py | 2 +- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/prolog/problems/lists/permute_2/en.py b/prolog/problems/lists/permute_2/en.py index 201d8d6..64203f4 100644 --- a/prolog/problems/lists/permute_2/en.py +++ b/prolog/problems/lists/permute_2/en.py @@ -13,4 +13,80 @@ description = '''\ L = [3,2,1]. ''' -hint = {} +plan = ['''\ +

+

Try recursively constructing one possibility, but leave prolog its freedom. It will then return +all the possibilities by itself.

+''', '''\ +

There are several options, one goes like this: if I take away the head, this reduces the problem and I can +leave it to recursion, and at the end I put the head back. Where do I put the head? I insert it in +all possible places, one solution at a time.

+''', '''\ +

If I assume the recursion permutes the tail T into the "permutated tail" +PT and then I insert head H somewhere into PT, then I will get +some permutation of the initial list [H|T].

+'''] + +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? What's the most elementary case? What if the list is empty?

+''', + + 'base_case_arbitrary': '''\ +

How can the result of permutating a list be an arbitrary list or an unassigned variable?

+

If your base case is reminiscent of permute([], _), rethink it! +What should be the result of permutating a list? +The base case always fully specifies the result, usually there are no unknowns (_ +or variables without assigned values) in what is being returned as the result.

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

Are you using conc/3? It's probably not so useful to solve this exercise, +but the solution to some other previous exercise might be what is required.

+''', + + 'forcing_result_onto_recursion': ''' +

Don't force the result onto recursion, don't tell it what it should return. Just let it be and +assume it will do its job. If this assumption is correct, then the rule will work for a larger case.

+

Is your recursive call of the form permute(T, [H|...])? This forces the recursive call to +also return the head H which it doesn't know of since you previously took it away. +Inserting the head into the result, returned by the recursive call, is your job. To put it shortly, +insert H outside of the recursive call.

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

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

+''', + + 'no_insert_or_delete': '''\ +

The base case is ok. However, what about the general recursive case? Perhaps it's a good idea +to reuse some previous exercise?

+''', + + '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 an empty list [] is equal to a list with +exactly three elements [A,B,C], +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/permute_2/sl.py b/prolog/problems/lists/permute_2/sl.py index 8cd11e9..ccf4cd7 100644 --- a/prolog/problems/lists/permute_2/sl.py +++ b/prolog/problems/lists/permute_2/sl.py @@ -59,7 +59,7 @@ rešena naloga.

Ne vsiljuj rekurziji kaj naj vrne, prepusti se ji. To je tisti del, ko narediš predpostavko, če je ta izpolnjena, potem bo tvoje pravilo delovalo za večji primer.

Je tvoj rekurzivni klic oblike permute(T, [H|...])? S tem vsiljuješ rekurziji -da mora vrniti tudi glavo, ki je sploh ne pozna, ker si jo ravnokar vzel stran! To moraš +da mora vrniti tudi glavo, ki je sploh ne pozna, ker si jo ravnokar vzel stran! To moraš narediti ti z rezultatom, ki ga rekurzija vrne. Skratka, element H dodaj izven rekurzivnega klica.

''', -- cgit v1.2.1 From c115ebcb77426b1983242cb095650657126a51ce Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Wed, 31 Aug 2016 23:30:35 +0200 Subject: English translation for divide/3 added. --- prolog/problems/lists/conc_3/en.py | 3 +- prolog/problems/lists/divide_3/en.py | 84 ++++++++++++++++++++++++++++++++++- prolog/problems/lists/insert_3/en.py | 3 +- prolog/problems/lists/permute_2/en.py | 3 +- 4 files changed, 85 insertions(+), 8 deletions(-) diff --git a/prolog/problems/lists/conc_3/en.py b/prolog/problems/lists/conc_3/en.py index c384222..be32b7d 100644 --- a/prolog/problems/lists/conc_3/en.py +++ b/prolog/problems/lists/conc_3/en.py @@ -60,8 +60,7 @@ or is it perhaps misspelled?

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 an empty list [] is equal to a list with -exactly three elements [A,B,C], -or something similarly impossible).

+exactly three elements [A,B,C], or something similarly impossible).

''', 'timeout': '''\ diff --git a/prolog/problems/lists/divide_3/en.py b/prolog/problems/lists/divide_3/en.py index f4cfa82..f47a51b 100644 --- a/prolog/problems/lists/divide_3/en.py +++ b/prolog/problems/lists/divide_3/en.py @@ -1,5 +1,5 @@ name = 'divide/3' -slug = 'split a list into parts of roughly equal length' +slug = 'split a list into two parts of roughly equal length' description = '''\

divide(L, L1, L2): the list L1 contains elements at odd positions in L, and the list L2 contains the elements at even positions in L.

@@ -10,4 +10,84 @@ description = '''\ X = [a,c,e], Y = [b,d,f]. ''' -hint = {} +plan = ['''\ +

+

You know... first, second, first, second, ...

+''', '''\ +

Can you pick two heads from the list's beginning? The pattern is [H1,H2|T].

+''', '''\ +

You take two elements from the list's beginning, the rest is recursively split, and then you +accordingly add those two elements into the recursion's result. By taking the two elements out, +you reduce (simplify) the problem and thus enable the recursion.

+''', '''\ +

If we assume the recursion splits the tail T into lists L1 and L2, +and upon returning the result we add H1 at the start of L1 and H2 +at the start of L2, then we get the split of the initial list of the form [H1,H2|T] +into two approximately equal parts.

+'''] + +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? What's the simplest possible case? What if the list is empty?

+''', + + 'base_case_arbitrary': '''\ +

How can the result of splitting a list be an arbitrary list(s) or an unassigned variable(s)?

+

If your base case is reminiscent of divide([], _, _) or divide([X], [X|_], ...), +rethink it! What should be the result of splitting? The base case always fully specifies the result, +usually there are no unknowns (_ or variables without assigned values) in what is being +returned as the result.

+''', + + 'second_base_case_missing': '''\ +

The recursion doesn't always succeed. Are there perhaps two different cases how it could end? You know, +odd and even ;) Do you need an extra base case? Try the following two queries; one will succeed, and the +other will fail.

+

?- divide([a,b,c], L1, L2).

+

?- divide([a,b,c,d], L1, L2).

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

Are you using conc/3? This is probably not a good idea here as conc/3 +splits the list in "blocks" and not on an element-by-element level. Rather try without it.

+''', + + 'forcing_result_onto_recursion': ''' +

Don't force the result onto recursion, don't tell it what it should return. Just let it be and +assume it will do its job. If this assumption is correct, then the rule will work for a larger case.

+

Is your recursive call of the form divide(T, [H1|...], [H2|...])? This forces the recursive call +to also return both heads that it doesn't know of since you previously took them away. +Adding those heads to the result, returned by the recursive call, is your job. To put it shortly, +add elements H1 and H2 outside the recursive call.

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

The base cases are 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 an empty list [] is equal to a list with +exactly three elements [A,B,C], 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/insert_3/en.py b/prolog/problems/lists/insert_3/en.py index d246932..f0a3e4a 100644 --- a/prolog/problems/lists/insert_3/en.py +++ b/prolog/problems/lists/insert_3/en.py @@ -56,8 +56,7 @@ or is it perhaps misspelled?

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 an empty list [] is equal to a list with -exactly three elements [A,B,C], -or something similarly impossible).

+exactly three elements [A,B,C], or something similarly impossible).

''', 'timeout': '''\ diff --git a/prolog/problems/lists/permute_2/en.py b/prolog/problems/lists/permute_2/en.py index 64203f4..ba20d67 100644 --- a/prolog/problems/lists/permute_2/en.py +++ b/prolog/problems/lists/permute_2/en.py @@ -81,8 +81,7 @@ or is it perhaps misspelled?

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 an empty list [] is equal to a list with -exactly three elements [A,B,C], -or something similarly impossible).

+exactly three elements [A,B,C], or something similarly impossible).

''', 'timeout': '''\ -- cgit v1.2.1 From 878daf66ab9c6257c0ef7e677e6c444813efca85 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Thu, 1 Sep 2016 16:19:09 +0200 Subject: English translation for shiftleft/2 added. --- prolog/problems/lists_advanced/shiftleft_2/en.py | 58 +++++++++++++++++++++++- prolog/problems/lists_advanced/shiftleft_2/sl.py | 2 +- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/prolog/problems/lists_advanced/shiftleft_2/en.py b/prolog/problems/lists_advanced/shiftleft_2/en.py index 6adbc12..9905cac 100644 --- a/prolog/problems/lists_advanced/shiftleft_2/en.py +++ b/prolog/problems/lists_advanced/shiftleft_2/en.py @@ -8,4 +8,60 @@ description = '''\ X = [2,3,4,5,1]. ''' -hint = {} +plan = ['''\ +

I take the first element of a list, let's call it H, and add it at the end of +the list's remainder (let's call the remainder T). As simple as that! You probably still +remember how we took the last element of the list? Adding an element is the same operation as taking it, +just from the opposite view ;)

+''', '''\ +

A list of length one is represented as a pattern [X]. This might come in handy, as well +as the predicate conc/3.

+''', '''\ +

If the given list L is composed of head H and tail T, and if +we add H at the end of T, then we get list L +shifted left.

+'''] + +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 shiftleft/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?

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

+''', + + 'conc_arg_not_list': '''\ +

All three arguments of predicate conc/3 are lists. +Are you sure you used it properly?

+''', + + 'arbitrary_result': '''\ +

Did you connect (use) all the variables? It seems as if you're returning an arbitrary result +(a variable without an assigned value). It's usually not a good idea to ignore the warning about +"singleton variables".

+''', + + 'tail_must_be_list': '''\ +

The list's tail is always another list and never an element!

+''', +} diff --git a/prolog/problems/lists_advanced/shiftleft_2/sl.py b/prolog/problems/lists_advanced/shiftleft_2/sl.py index aa83672..aa116ee 100644 --- a/prolog/problems/lists_advanced/shiftleft_2/sl.py +++ b/prolog/problems/lists_advanced/shiftleft_2/sl.py @@ -24,7 +24,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.

+shiftleft/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 1b2c914d8552f4af1676f6b63203513d949c7817 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Thu, 1 Sep 2016 18:36:34 +0200 Subject: English translation for shiftright/2 added. --- prolog/problems/lists_advanced/shiftright_2/en.py | 66 ++++++++++++++++++++++- prolog/problems/lists_advanced/shiftright_2/sl.py | 2 +- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/prolog/problems/lists_advanced/shiftright_2/en.py b/prolog/problems/lists_advanced/shiftright_2/en.py index 4e0fec3..21b404d 100644 --- a/prolog/problems/lists_advanced/shiftright_2/en.py +++ b/prolog/problems/lists_advanced/shiftright_2/en.py @@ -8,4 +8,68 @@ description = '''\ X = [5,1,2,3,4]. ''' -hint = {} +plan = ['''\ +

I take the last element from the given list and add it back at the start of the list's remainder. +You probably still remember how we took the last element of the list? And adding an element at the start +is quite simple, isn't it?

+''', '''\ +

A list of length one is represented as a pattern [X]. This might come in handy, as well +as the predicate conc/3.

+''', '''\ +

If the given list L is composed of last element E and the remainder L1, +and if we put E at the start of L1, then we get list L +shifted right.

+'''] + +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 shiftleft/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?

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

+''', + +'conc_2nd_argument_not_1elem_list': '''\ +

Do you remember how the "pattern" representing a list with exactly one element looks like? Not like +the second argument you gave to predicate conc/3. ;)

''', + + 'arbitrary_result': '''\ +

Did you connect (use) all the variables? It seems as if you're returning an arbitrary result +(a variable without an assigned value). It's usually not a good idea to ignore the warning about +"singleton variables".

+''', + +'shiftleftish_solution': '''\ +

The tail of the list is always another list and never just an element. How did you get the last +element? This will not work...

''', + +'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. Rather try using predicate conc/3 instead.

''', + +'final_hint': '''\ +

Predicates shiftleft/2 and shiftright/2 perform exactly the opposite function. +If you simply swap the order of their arguments, you get the other predicate. In this way you could +program shiftright/2 just by calling shiftleft/2. You know that in prolog inputs +and outputs can often be interchanged.

''', +} diff --git a/prolog/problems/lists_advanced/shiftright_2/sl.py b/prolog/problems/lists_advanced/shiftright_2/sl.py index ce9b9fa..784f4ed 100644 --- a/prolog/problems/lists_advanced/shiftright_2/sl.py +++ b/prolog/problems/lists_advanced/shiftright_2/sl.py @@ -24,7 +24,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.

+shiftright/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 0974e756466142e8a24020f5ff4c3391143b73c2 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Tue, 6 Sep 2016 00:03:16 +0200 Subject: English translation for len/2 added. --- prolog/problems/lists_advanced/len_2/en.py | 85 +++++++++++++++++++++++++++++- prolog/problems/lists_advanced/len_2/sl.py | 2 +- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/prolog/problems/lists_advanced/len_2/en.py b/prolog/problems/lists_advanced/len_2/en.py index 9202c2d..33b1675 100644 --- a/prolog/problems/lists_advanced/len_2/en.py +++ b/prolog/problems/lists_advanced/len_2/en.py @@ -2,10 +2,91 @@ name = 'len/2' slug = 'find the length of a list' description = '''\ -

len(L, Len): Len is the length of the list L.

+

len(L, Len): Len is the length of list L.

 ?- len([1,2,3], Len).
   Len = 3.
 
''' -hint = {} +plan = ['''\ +

A list is not very long if it's empty, and if it's not empty it must have a head and a tail.

+''', '''\ +

If the tail (list without a head) is of length LenT, then the whole list +is of length LenT + 1.

+''', '''\ +

If I take away the head, and the recursion solves this smaller problem (tail), and if I add 1 to the +result returned by the recursion, then I got the length of the whole list.

+'''] + +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 conc/3 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? Which list is the shortest list in the world?

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

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

What's the length of an empty list? Give a number!

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

The error that prolog reported means that when it encountered an arithmetic operation, not all the +values were known. Unfortunately, the ordering of goals is important when dealing with arithmetics.

+

Perhaps you can try moving the arithmetic operation more towards the end of the predicate?

+''', + + '=_instead_of_is': '''\ +

Did you use the operator = instead of is? Operator = is used for +unification and tries to leave both its operands with as little modifications as possible while still making +them equal. Operator is, on the other hand, performs actual arithmetic evaluation of its +second operand and only then attempts the unification of both operands.

+''', + + '+H_instead_of_+1': '''\ +

Did you really add the element's value instead of its length (one)? ;)

+''', + + 'forcing_result_onto_recursion': ''' +

Don't force the result onto recursion, don't tell it what it should return. Just assume it will do its job. +If this assumption is correct, then the rule will work for a larger case.

+

Is your recursive call of the form len(T, LenT + 1)? This forces the recursive call to +return the length of the whole list, not just the tail! This will not work. It is your job to +increase by one the result returned by the recursion. In short, add one outside the recursive call.

+''', + + 'same_var_on_both_sides_of_is': '''\ +

Does one of your goals look similar to N is N + 1? Let's assume N is equal to 3. +With this goal you just stated that 3 must be equal to 4 (3+1). Prolog is a logical language and will +gladly say "false" to such a statement! Just use a new variable. The garbage collector will take care of +those not needed anymore automatically.

+''', +} diff --git a/prolog/problems/lists_advanced/len_2/sl.py b/prolog/problems/lists_advanced/len_2/sl.py index c95796b..49b9eea 100644 --- a/prolog/problems/lists_advanced/len_2/sl.py +++ b/prolog/problems/lists_advanced/len_2/sl.py @@ -21,7 +21,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.

+len/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 d259285459176fc281193adb12483a6e6d527cf5 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Tue, 6 Sep 2016 16:48:08 +0200 Subject: English translation for sum/2 added. --- prolog/problems/lists_advanced/len_2/en.py | 6 +-- prolog/problems/lists_advanced/len_2/sl.py | 4 +- prolog/problems/lists_advanced/sum_2/en.py | 87 +++++++++++++++++++++++++++++- prolog/problems/lists_advanced/sum_2/sl.py | 6 +-- 4 files changed, 93 insertions(+), 10 deletions(-) diff --git a/prolog/problems/lists_advanced/len_2/en.py b/prolog/problems/lists_advanced/len_2/en.py index 33b1675..6518eec 100644 --- a/prolog/problems/lists_advanced/len_2/en.py +++ b/prolog/problems/lists_advanced/len_2/en.py @@ -15,14 +15,14 @@ plan = ['''\ is of length LenT + 1.

''', '''\

If I take away the head, and the recursion solves this smaller problem (tail), and if I add 1 to the -result returned by the recursion, then I got the length of the whole list.

+result returned by the recursion, then I get the length of the whole list.

'''] 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 conc/3 more general (e.g. able to work with output arguments becoming inputs).

+you can make the predicate len/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).

''', @@ -78,7 +78,7 @@ second operand and only then attempts the unification of both operands.

'forcing_result_onto_recursion': '''

Don't force the result onto recursion, don't tell it what it should return. Just assume it will do its job. If this assumption is correct, then the rule will work for a larger case.

-

Is your recursive call of the form len(T, LenT + 1)? This forces the recursive call to +

Is your recursive call of the form len(Tail, LenTail + 1)? This forces the recursive call to return the length of the whole list, not just the tail! This will not work. It is your job to increase by one the result returned by the recursion. In short, add one outside the recursive call.

''', diff --git a/prolog/problems/lists_advanced/len_2/sl.py b/prolog/problems/lists_advanced/len_2/sl.py index 49b9eea..28fe25e 100644 --- a/prolog/problems/lists_advanced/len_2/sl.py +++ b/prolog/problems/lists_advanced/len_2/sl.py @@ -75,8 +75,8 @@ svoji levi strani.

'forcing_result_onto_recursion': '''

Ne vsiljuj rekurziji kaj naj vrne, prepusti se ji. To je tisti del, ko narediš predpostavko, če je ta izpolnjena, potem bo tvoje pravilo delovalo za večji primer.

-

Je tvoj rekurzivni klic oblike len(T, LenT + 1)? S tem vsiljuješ rekurziji -da mora vrniti dolžino celega seznama in ne samo repa. To ni v redu, za ena moraš ti povečati +

Je tvoj rekurzivni klic oblike len(Tail, LenTail + 1)? S tem vsiljuješ rekurziji +da mora vrniti dolžino celega seznama in ne samo repa. To ni v redu, za ena moraš ti povečati rezultat, ki ti ga rekurzija vrne. Skratka, prištevanje naredi izven rekurzivnega klica.

''', diff --git a/prolog/problems/lists_advanced/sum_2/en.py b/prolog/problems/lists_advanced/sum_2/en.py index 767a6f4..3abc348 100644 --- a/prolog/problems/lists_advanced/sum_2/en.py +++ b/prolog/problems/lists_advanced/sum_2/en.py @@ -2,10 +2,93 @@ name = 'sum/2' slug = 'find the sum of all elements in list' description = '''\ -

sum(L, Sum): Sum is the sum of all elements in the list L.

+

sum(L, Sum): Sum is the sum of all elements in list L.

 ?- sum([1,2,3], Sum).
   Sum = 6.
 
''' -hint = {} +plan = ['''\ +

The sum of an empty list is really not all that large. And if it's not empty, then we add it up, +element by element, recursively.

+''', '''\ +

If the sum of the elements in the tail (list without a head) equals SumT, then the sum +of the elements in the whole list equals SumT + H.

+''', '''\ +

If I take away the head, and the recursion solves this smaller problem (tail), and if I add the value +of the head to the result returned by the recursion, then I get the sum of the whole list.

+'''] + +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 sum/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 sum of the elements in an empty list?

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

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

What's the sum of the elements in an empty list? Give a number!

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

The error that prolog reported means that when it encountered an arithmetic operation, not all the +values were known. Unfortunately, the ordering of goals is important when dealing with arithmetics.

+

Perhaps you can try moving the arithmetic operation more towards the end of the predicate?

+''', + + '=_instead_of_is': '''\ +

Did you use the operator = instead of is? Operator = is used for +unification and tries to leave both its operands with as little modifications as possible while still making +them equal. Operator is, on the other hand, performs actual arithmetic evaluation of its +second operand and only then attempts the unification of both operands.

+''', + + '+1_instead_of_+H': '''\ +

Did you really add one instead of the element's value? Copy/paste operation from the previous exercise? ;)

+''', + + 'forcing_result_onto_recursion': ''' +

Don't force the result onto recursion, don't tell it what it should return. Just assume it will do its job. +If this assumption is correct, then the rule will work for a larger case.

+

Is your recursive call of the form sum(Tail, SumTail + H)? This forces the recursive call to +return the sum of the whole list, not just the tail! This will not work. It is your job to +increase (by value of the head) the result returned by the recursion. In short, perform the addition +outside the recursive call.

+''', + + 'same_var_on_both_sides_of_is': '''\ +

Does one of your goals look similar to N is N + 1? Let's assume N is equal to 3. +With this goal you just stated that 3 must be equal to 4 (3+1). Prolog is a logical language and will +gladly say "false" to such a statement! Just use a new variable. The garbage collector will take care of +those not needed anymore automatically.

+''', +} diff --git a/prolog/problems/lists_advanced/sum_2/sl.py b/prolog/problems/lists_advanced/sum_2/sl.py index 539271b..d3bddcf 100644 --- a/prolog/problems/lists_advanced/sum_2/sl.py +++ b/prolog/problems/lists_advanced/sum_2/sl.py @@ -22,7 +22,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.

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

''', @@ -76,8 +76,8 @@ svoji levi strani.

'forcing_result_onto_recursion': '''

Ne vsiljuj rekurziji kaj naj vrne, prepusti se ji. To je tisti del, ko narediš predpostavko, če je ta izpolnjena, potem bo tvoje pravilo delovalo za večji primer.

-

Je tvoj rekurzivni klic oblike len(T, LenT + H)? S tem vsiljuješ rekurziji -da mora vrniti vsoto celega seznama in ne samo repa. To ni v redu, za vrednost glave moraš ti povečati +

Je tvoj rekurzivni klic oblike sum(Tail, SumTail + H)? S tem vsiljuješ rekurziji +da mora vrniti vsoto celega seznama in ne samo repa. To ni v redu, za vrednost glave moraš ti povečati rezultat, ki ti ga rekurzija vrne. Skratka, prištevanje naredi izven rekurzivnega klica.

''', -- cgit v1.2.1 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/max_2/en.py | 87 ++++++++++++++++++++++++++++- prolog/problems/lists_advanced/max_2/sl.py | 5 +- prolog/problems/lists_advanced/min_2/en.py | 89 +++++++++++++++++++++++++++++- prolog/problems/lists_advanced/min_2/sl.py | 7 ++- 4 files changed, 178 insertions(+), 10 deletions(-) diff --git a/prolog/problems/lists_advanced/max_2/en.py b/prolog/problems/lists_advanced/max_2/en.py index 59c00f0..fbdc612 100644 --- a/prolog/problems/lists_advanced/max_2/en.py +++ b/prolog/problems/lists_advanced/max_2/en.py @@ -2,7 +2,7 @@ name = 'max/2' slug = 'find the largest element in list' description = '''\ -

max(L, Max): Max is the largest value in the list L.

+

max(L, Max): Max is the largest value in list L.

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

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

+''', '''\ +

Compare the largest element in the tail (list without head H) with the value of head H, +the larger 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 MaxT is the largest element in T, and if it's also true that +the value of H is greater than MaxT, then H is the largest element +in L. Or it is true that H is smaller than MaxT, and in this +case MaxT is the largest 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 max/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 largest 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 largest 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.

+

?- max([6,9,3,8,1], Max).

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

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

+''', +} diff --git a/prolog/problems/lists_advanced/max_2/sl.py b/prolog/problems/lists_advanced/max_2/sl.py index 0553e58..abd6cc5 100644 --- a/prolog/problems/lists_advanced/max_2/sl.py +++ b/prolog/problems/lists_advanced/max_2/sl.py @@ -11,7 +11,8 @@ description = '''\ ''' plan = ['''\ -

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

+

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

''', '''\

Največji element v repu (seznamu brez glave H) primerjaj z vrednostjo glave H, tisti, ki je večji 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.

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

''', 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 29a65937bab5416adc060b9bf60652cff91276c0 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Thu, 8 Sep 2016 19:09:21 +0200 Subject: English translations for evenlen/1 and oddlen/1 added. --- .../lists_advanced/evenlen_1_+_oddlen_1/en.py | 71 +++++++++++++++++++++- .../lists_advanced/evenlen_1_+_oddlen_1/sl.py | 7 ++- 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/en.py b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/en.py index 7e7a7d3..601488a 100644 --- a/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/en.py +++ b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/en.py @@ -1,9 +1,10 @@ name = 'evenlen/1 + oddlen/1' -slug = 'check if the length of a list is even or odd' +slug = 'check if the length of a list is even or odd (without arithmetics)' description = '''\

evenlen(L): the list L has an even number of elements.
oddlen(L): the list L has an odd number of elements.

+

Don't use arithmetic operations with this exercise, it destroys the point of it!

 ?- oddlen([1,2,3,4,5]).
   true.
@@ -13,4 +14,70 @@ description = '''\
   true.
 
''' -hint = {} +plan = ['''\ +

You can solve this exercise as two separate, albeit similar, ones, or as a single exercise that +intertwines two predicates. The second option is probably more interesting.

+''', '''\ +

Intertwining in this case means that one predicate calls the other and vice versa. Even. Odd. Even. Odd.

+''', '''\ +

If the tail (list without a single head) is of even length, then the whole list is of +odd length. And vice versa.

+'''] + +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 predicates oddlen/1 and evenlen/1 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 simplest case that you can trivially solve?

+''', + + 'extra_base_case': '''\ +

You're getting duplicate solutions. It's enough to only have a single base case for this pair of +predicates; you don't need one for evenlen/1 and one for oddlen/1.

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

It seems that you accept an arbitrary result (a variable without an assigned value). This will not be ok.

+

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

+''', + + 'arithmetics_used': '''\ +

Please don't use arithmetics to solve this exercise, not even for counting the length of the list. +It can be solved without that and it's also a much nicer idea or two.

+''', + +'odd_and_even_mixed_up': '''\ +

Did you mix up odd and even? Zero is even, one is odd, two is... ;)

+''', + + '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/evenlen_1_+_oddlen_1/sl.py b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/sl.py index 000ce1a..1c0b596 100644 --- a/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/sl.py +++ b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/sl.py @@ -4,6 +4,7 @@ slug = 'Brez aritmetike preveri, če je seznam sode ali lihe dolžine' description = '''\

evenlen(L): seznam L ima sodo število elementov.
oddlen(L): seznam L ima liho število elementov.

+

Ne uporabljaj aritmetike pri tej nalogi, ker to uniči njeno poanto!

 ?- oddlen([1,2,3,4,5]).
   true.
@@ -19,15 +20,15 @@ Druga verzija je verjetno bolj zanimiva.

''', '''\

Prepletanje tu pomeni, da ena naloga kliče drugo in obratno. Sodo. Liho. Sodo. Liho.

''', '''\ -

Če je rep (seznam brez ene glave) sode dolžine, potem je celoten seznam lihe dolžine. +

Če je rep (seznam brez ene glave) sode dolžine, potem je celoten seznam lihe dolžine. In obratno.

'''] 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). Morda z uporabo = narediš predikata +oddlen/1 in evenlen/1 delujoča 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 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(-) 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 +- 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(-) 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 From b334f31758ea177028ba33648f6515edb282a0ce Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Fri, 9 Sep 2016 11:29:54 +0200 Subject: Use LaTeX math for python/introduction/ballistics --- python/problems/introduction/ballistics/sl.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/problems/introduction/ballistics/sl.py b/python/problems/introduction/ballistics/sl.py index ac5de23..b0f33e7 100644 --- a/python/problems/introduction/ballistics/sl.py +++ b/python/problems/introduction/ballistics/sl.py @@ -9,8 +9,8 @@ description = '''\ točkaste krogle v brezzračnem prostoru, a pustimo trivio). Program od uporabnika ali uporabnice zahteva, da vnese kot, pod katerim je izstreljen, in hitrost izstrelka. Program naj izračuna in izpiše, kako daleč bo letela krogla.

-

Pomoč za fizično nebogljene: s=v2sin(2f)/g , kjer je s razdalja, -v hitrost izstrelka, f je kot, g pa gravitacijska konstanta (9,8).

+

Pomoč za fizično nebogljene: \( s=v^2 \\sin(2f)/g \), kjer je \(s\) razdalja, +\(v\) hitrost izstrelka, \(f\) kot, \(g\) pa gravitacijska konstanta (9.8).

Preveri tole: krogla leti najdalj, če jo izstrelimo pod kotom 45 stopinj. Poskusi, kako daleč gre pod kotom 45 in kako daleč pod 46 stopinj -- po 45 mora leteti dlje. Preveri tudi kot 50 stopinj: če pod tem kotom leti nazaj (razdalja je negativna), @@ -19,7 +19,7 @@ si ga gotovo nekje polomil. ''' eval_expression = ['''\ -

Dolžino strela dobiš po formuli: s=v2sin(2f)/g.

''', +

Dolžino strela dobiš po formuli: \( s=v^2 \\sin(2f)/g \).

''', '''\

Funkcijo sin dobiš v modulu math, kot smo tam dobili funkcijo sqrt. Na začetku napiši:

@@ -57,14 +57,14 @@ hint = {

Poskusi sin(30). Zakaj je rezultat negativen?

''', '''\

Vse triginometrične funkcije sprejemajo kot v radianih in ne v stopinjah.

''', -'''

V stopinjah ima cel krog 360°, v radianih pa 2*pi.

''', +'''

V stopinjah ima cel krog 360°, v radianih pa \( 2 \\pi \).

''', '''

Formula za pretvorbo med stopinjami in radiani je:

 kot_rad = kot * 2 * pi / 360
 
'''], - 'betterg': '''Konstanta g naj ima vrednost 9.8''', + 'betterg': '''Konstanta \(g\) naj ima vrednost 9.8''', 'name_error' : [mod.general_msg['error_head'], mod.general_msg['general_exception'], mod.general_msg['name_error'], ''' -- 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/len_2/en.py | 2 +- prolog/problems/lists_advanced/min_2/en.py | 2 +- prolog/problems/lists_advanced/rev_2/en.py | 2 +- prolog/problems/sorting/isort_2/en.py | 55 +++++++++++++++++++++++++++++- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/prolog/problems/lists_advanced/len_2/en.py b/prolog/problems/lists_advanced/len_2/en.py index 6518eec..98eac2a 100644 --- a/prolog/problems/lists_advanced/len_2/en.py +++ b/prolog/problems/lists_advanced/len_2/en.py @@ -40,7 +40,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?

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?

diff --git a/prolog/problems/lists_advanced/rev_2/en.py b/prolog/problems/lists_advanced/rev_2/en.py index dbb08a2..790d664 100644 --- a/prolog/problems/lists_advanced/rev_2/en.py +++ b/prolog/problems/lists_advanced/rev_2/en.py @@ -44,7 +44,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?

diff --git a/prolog/problems/sorting/isort_2/en.py b/prolog/problems/sorting/isort_2/en.py index 71b1a12..35beb62 100644 --- a/prolog/problems/sorting/isort_2/en.py +++ b/prolog/problems/sorting/isort_2/en.py @@ -8,4 +8,57 @@ description = '''\ L = [1,2,3,4,5]. ''' -hint = {} +plan = ['''\ +

When going through the list (actually when returning from recursion) at every step insert the current element +in its proper position.

+''', '''\ +

When going through the list at every step take away the head (it's stored on stack), while its tail goes +into recursion (the problem/list is shorter, so this is possible). The recursion returns the sorted +tail, and all that's left for you to do is to put the previously taken away head into its proper place in the +sorted tail. Of course you can reuse some previous exercise for this task.

+''', '''\ +

If list L is composed of head H and tail T and if we assume that +tail T is correctly sorted into SortedTail by recursion, and if head H +is inserted into its proper place within SortedTail, then we get the whole list L +properly sorted.

+'''] + +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 can you sort without any effort whatsoever?

+''', + + '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 X is simultaneously smaller and greater than +Y, 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?

+''', + + 'min_used': '''\ +

Try solving this exercise without using the predicate min/2.

+''', +} -- cgit v1.2.1 From 8cbbbe0a57068556fb8195c8c47a998a51599d8d Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Wed, 21 Sep 2016 23:34:56 +0200 Subject: English translation for slowest_sort_ever/2 added. --- prolog/problems/sorting/slowest_sort_ever_2/en.py | 44 ++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/prolog/problems/sorting/slowest_sort_ever_2/en.py b/prolog/problems/sorting/slowest_sort_ever_2/en.py index 0e359b4..72a70bb 100644 --- a/prolog/problems/sorting/slowest_sort_ever_2/en.py +++ b/prolog/problems/sorting/slowest_sort_ever_2/en.py @@ -8,4 +8,46 @@ description = '''\ L = [1,2,3,4,5]. ''' -hint = {} +plan = ['''\ +

This exercise is mostly for fun... all you need are two lines, i.e. two prolog goals.

+''', '''\ +

Perhaps you can reuse some previous solutions?

+''', '''\ +

Which of the previous solutions has time complexity of O(n!)? Use it!

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

+''', + + '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 X is simultaneously smaller and greater than +Y, 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?

+''', + + 'no_permute': '''\ +

Hmmm, which of the previous exercises has time complexity of O(n!)? How can you use it here?

+''', + + 'no_isSorted': '''\ +

You're on the right path, just a bit more to go. Perhaps you can reuse another previous exercise?

+''', +} -- cgit v1.2.1 From 236500bc03d18b10f0989e052f4e829b52ad03f0 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Fri, 23 Sep 2016 18:49:19 +0200 Subject: English translation for quicksort/2 added. --- prolog/problems/sorting/quick_sort_2/en.py | 59 +++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/prolog/problems/sorting/quick_sort_2/en.py b/prolog/problems/sorting/quick_sort_2/en.py index aa3eb44..a5b571b 100644 --- a/prolog/problems/sorting/quick_sort_2/en.py +++ b/prolog/problems/sorting/quick_sort_2/en.py @@ -8,4 +8,61 @@ description = '''\ L = [1,2,3,4,5]. ''' -hint = {} +plan = ['''\ +

Divide and conquer! And use previous solutions, of course. :)

+''', '''\ +

Take the head away, use it as a pivot, divide the tail into smaller and larger elements. Use recursion on +so obtained sublists since both are shorter (in the worst case scenario shorter by just the head element -- +this also explains why quicksort works worst on already sorted lists). In the end simply combine the sublists.

+''', '''\ +

If list L is composed of head P and tail T and if the tail is +split into sublists containing smaller and larger elements, respectively, based on pivot P, and if +we assume the recursion sorts these two sublists into lists SortedSmallerElems and +SortedGreaterElems, and if finally we concatenate these two lists and add in between pivot/head +P, then this results in correctly sorted initial list 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).

+

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 can you sort without any effort whatsoever?

+''', + + '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 X is simultaneously smaller and greater than +Y, 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?

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

How can the sorted list be anything whatsoever or a list with an arbitrary element? Did you use +a variable without an assigned value?

+''', + + 'forgotten_pivot': '''\ +

Did you, perhaps, forgot to put the pivot element back into the list when returning from recursion?

+''', +} -- cgit v1.2.1 From 3bfcb3e651980f1675807b8f82826dcb3e4e1013 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Tue, 27 Sep 2016 02:06:15 +0200 Subject: English translation for is_sorted/1 added. --- prolog/problems/sorting/is_sorted_1/en.py | 81 ++++++++++++++++++++++++++++++- prolog/problems/sorting/is_sorted_1/sl.py | 2 +- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/prolog/problems/sorting/is_sorted_1/en.py b/prolog/problems/sorting/is_sorted_1/en.py index 8741bc7..678494c 100644 --- a/prolog/problems/sorting/is_sorted_1/en.py +++ b/prolog/problems/sorting/is_sorted_1/en.py @@ -10,4 +10,83 @@ description = '''\ false. ''' -hint = {} +plan = ['''\ +

As always try to reduce the problem onto a smaller one. Do an appropriate check (comparison) at +the start of the list, and submit the tail to a recursive check.

+''', '''\ +

You do know how to access the first two elements of the list, right? And the arithmetic comparison +operators were introduced in the previous batch of exercises.

+''', '''\ +

If the given list L is composed of heads H1 and H2 and of tail +T, and if we assume that tail T along with the second head is sorted, and furthermore +H1 is smaller or equal to H2, then the whole list L is sorted.

+'''] + +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 is one of the shortest sorted lists?

+''', + + '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 X is simultaneously smaller and greater than +Y, 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?

+''', + + '[]_base_case_missing': '''\ +

For completeness, please take care of the special case, i.e. the empty list which is also sorted. +But be careful not to destroy the other solutions.

+''', + + 'duplicates_fail': '''\ +

Did you forget about duplicate elements? The list below is also sorted!

+

?- is_sorted([25,25,25,25]).

+''', + + 'H1_instead_of_H2_sent_into_recursion': '''\ +

Did you send the wrong of the two list heads into recursion?

+''', + + 'base_case_at_len_1_missing': '''\ +

The recursive case in this exercise requires two elements, even though you put one back when the tail +is recursively processed. But what happens when there is just a single element left in the list? Think +about it as this will probably be the main base case.

+''', + + 'both_heads_omitted_from_recursion': '''\ +

Are you taking two elements out of the list before initiating a recursive call? You're trying to +reduce the number of comparisons, aren't you? ;) But unfortunately this will not be possible! Of the following +two cases below one works correctly and one doesn't. What's the difference between them?

+

?- is_sorted([1,3,14,16,24,25]).

+

?- is_sorted([24,25,14,16,1,3]).

+''', + + 'min_used': '''\ +

Try solving this exercise without using the predicate min/2. Your solution should have the +time complexity of O(n). By using min/2 the complexity is typically about O(n*n).

+''', +} diff --git a/prolog/problems/sorting/is_sorted_1/sl.py b/prolog/problems/sorting/is_sorted_1/sl.py index de52984..36ace61 100644 --- a/prolog/problems/sorting/is_sorted_1/sl.py +++ b/prolog/problems/sorting/is_sorted_1/sl.py @@ -77,7 +77,7 @@ glavni robni pogoj!

'both_heads_omitted_from_recursion': '''\

Jemlješ po dva elementa iz seznama preden greš v rekurzijo? Poskušaš malce prihraniti pri primerjavah, kajne? ;) -Ampak žal to ne gre! Od spodnjih dveh primerov eden deluje pravilno in eden ne, ugotovi v čem je razlika.

+Ampak žal to ne gre! Od spodnjih dveh primerov eden deluje pravilno in eden ne, ugotovi v čem je razlika.

?- is_sorted([1,3,14,16,24,25]).

?- is_sorted([24,25,14,16,1,3]).

''', -- cgit v1.2.1