6. Write Prolog clauses that define each of the following predicates: a. exactly_3(x) is true if x...

Question:

6. Write Prolog clauses that define each of the following predicates:

a. exactly_3(x) is true if x is a list with exactly three elements.

b. at_least_3(x) is true if x is a list with at least three elements.

c. at_most_3(x) is true if x is list with at most three elements.

Hint: Use four clauses.

d. intersect(x, y) is true if x and y are lists with an element in common.

intersect([1,2,3,4],[5,4,1,6]) holds, but intersect([1,2,3,4],[5,6]) does not hold.

Hint: Use member but no recursion.

e. all_intersect(z, y) is true if every element of list z is a list x such that intersect(x, y) holds.

all_intersect([[1,2,3],[5,4,6]],[3,4]) holds, and all_intersect([],[3,4]) holds, but all_intersect([[1,2,3],[1,2,5],[5,4,6]],[3,4]) does not hold.

Hint: Use intersect and recursion.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: