Question: PROLOG multiple choice questions please answer with full explanations 18. What is the following mystery/2 about? mystery([],[]). mystery([X|Y],Z) :- mystery(Y,W), takeout(X,Z,W). takeout(X,[X|R],R). takeout(X,[F|R],[F|S]) :- takeout(X,R,S).

PROLOG multiple choice questions

please answer with full explanations

18. What is the following mystery/2 about? mystery([],[]). mystery([X|Y],Z) :- mystery(Y,W), takeout(X,Z,W). takeout(X,[X|R],R). takeout(X,[F|R],[F|S]) :- takeout(X,R,S).

A. append

B. prefix

C. permutation

D. reverse

E. suffix

F. member

G. sort

19. Consider the following query. It will have ___ answer(s). ?- member(X,[1,2,3,4]), Y = X*X, Y<10.

A. 0

B. 1

C. 2

D. 3

E. 4

20. Consider the following mystery/3 predicate.

mystery(X,[X|R],R). mystery(X,[F|R],[F|S]) :- mystery(X,R,S).

What is the result L of the following query: ?- mystery(1,[1,2,3], L).

A. L=1

B. L=2

C. L=3

D. L=[2,3]

E. L=[1,1,2,3]

F. L=[1]

22 Which of the following selections is correct? This ____ is to add a new fact or rule (clause).

A. args/3

B. assert/1

C. atom/1

D. clause/2

E. call/1

F. findall/3

G. functor/3

H. ground/1

I. op/3

J. retract/1, retractall/1

K. var/1

L. =, \=

M. ==, \==

23. What is the predicate ___ for the following query and its result? ?- ____(f(a,b),F,A). A = 2 F = f

A. args/3

B. assert/1

C. atom/1

D. clause/2

E. call/1

F. findall/3

G. functor/3

H. ground/1

I. op/3

J. retract/1

K. var/1

L. =, \=

M. ==, \==

24. What is the predicate ___ for the following query and its result? ?- ___(2,loves(richard, sarah), X). X = sarah

A. arg/3

B. assert/1

C. atom/1

D. clause/2

E. call/1

F. findall/3

G. functor/3

H. ground/1

I. op/3

J. retract/1

K. var/1

L. =, \=

M. ==, \==

27. Complete the second clause of the following Prolog program for member/2 where member(X, Y) checks whether X is an element (a member) of a list Y. member(X,[X|R]). member(X,[Y|R]) :- ____________.

A. member(X,R).

B. member(X,Y).

C. member(_,R).

D. member(Y,R).

E. member(X,Y).

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!