Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions