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(-) (limited to 'prolog') 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