Devam Ediyor

Prolog basic exercise

You will implement the following Prolog predicates.

1. replace(E1, L1, E2, L2)

this holds when list L1 is the same as L2, except that in one place where L1 has the value E1, L2 has E2. Note that only one occurrence of E1 is replaced. This must work in any mode in which at least one of L1 or L2 is a proper list (that is, either [] or a list whose tail is a proper list). For example:

replace(2,[1,2,3,4],5,X) should have only the solution X = [1,5,3,4]. replace(2,[1,2,3,2,1],5,X) should backtrack over the solutions X = [1,5,3,2,1]

and X = [1,2,3,5,1].

replace(2,X,5,[1,5,3,5,1]) should backtrack over the solutions X = [1,2,3,5,1]

and X = [1,5,3,2,1].

replace(X,[a,b,c,d],Y,[a,e,c,d]) should have only the solution X = b, Y = e. replace(X,[1,2,3,2,1],Y,[1,5,3,5,1]) should have no solutions (it should fail).

2. zip(As, Bs, ABs)

this holds when As, Bs, and ABs are lists of the same length, and each element of ABs is a term of the form A-B where A is the corresponding element of As and B is the corresponding element of Bs. This should work whenever at least one of the arguments is a proper list. Note that - is an infix operator here, but aside from syntax, A-B is an ordinary term whose functor is - and whose two arguments are A and B. For example:

zip([1,2,3,4],[a,b,c,d],L) should have only the solution L=[1-a,2-b,3-c,4-d]]. zip(X,Y,[1-a,2-b,3-c,4-d]) shouldhaveonlythesolutionX=[1,2,3,4], Y=[a,b,c,d]. zip([1,2,3,4],Y,[1-a,2-b,3-c,4-d]) should have only the solution Y=[a,b,c,d].


zip(X,[a,b,c,d],[1-P,2-Q,3-R,4-S]) should have only the solution X=[1,2,3,4], P=a, Q=b, R=c, S=d.

zip([1,2,3],[a,b,c,d],L) should fail.

3. sublist(Xs, Ys)

this holds when Xs is a list containing some of the elements of Ys, in the same order they appear in the list Ys. This should work whenever Ys is a proper list. For example:

sublist([a,c,e],[a,b,c,d,e]) should succeed.

sublist([a,e,c],[a,b,c,d,e]) should fail.

sublist([a,X,d],[a,b,c,d,e]) should have the two solutions X=b and X=c.

sublist(X,[a,b,c]) should have the eight solutions X=[]; X=[c]; X=[b]; X=[b,c]; X=[a]; X=[a,c]; X=[a,b]; and X=[a,b,c].

Note that the order in which solutions are found does not matter, but all listed answers must be found, and no extra solutions are permitted.

You must call your source file

Beceriler: Prolog

Daha fazlasını görün: l2, d&p solutions, r in operator, ys, exercise, basic matlab exercise, spend analysis excel basic complex supply chain exercise, basic java exercise, techno basic elements ableton, basic elements coupon site, basic excel exercise, matlab basic exercise, give basic elements parts microsoft word, E1, backtrack, java basic exercise, basic order form, hospital management sample forms visual basic

İşveren Hakkında:
( 2 değerlendirme ) melbourne, Australia

Proje NO: #6558188

0 freelancer bu iş için ortalamada $ teklif veriyor


I have not yet completed projects in this forum, but some of the projects should be first. Maybe it is your project? From the Prolog, of course, familiar. Swi? Visual? Turbo?

in 2 gün içinde30$ AUD
(16 Değerlendirme)