Question: /* Problem 7 : Write a predicate delete_at(E,Y,N,Z) that succeeds if Z is the list Y with E delete at index N -- Delete E

/* Problem 7 : Write a predicate delete_at(E,Y,N,Z) that succeeds if Z is the list Y with E delete at index N -- Delete E at index N in Y. YOU MUST USE the predicate defined in the above problem to solve this problem.

NOTE: Don't worry about the error cases: i.e, N greater than the length of Z. */

/* Problem 7 Test: */

%:- delete_at(3,[1,2,3,3],2,[1,2,3]). % SUCCEED %:- delete_at(1,[1,1,2,3],0,[1,2,3]). % SUCCEED %:- delete_at(a,[1,a,2,3],1,[1,2,3]). % SUCCEED

%:- delete_at(1,[1,2,3],0,[1,2,3]) -> fail ; true. % FAIL

/* Problem 8: Write a predicate zip(Xs,Ys,Zs) that succeeds if Zs is a list where each element is a tuple, (X,Y), with Xs and Ys paired together.

For example... zip([1,2,3],[a,b,c],Zs) should give Zs = [(1,a),(2,b),(3,c)] zip([1],[a],Zs) should give Zs = [(1,a)]

NOTE: You may assume X and Y have the same length. */

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!