University of Lethbridge

CS 3750

EXERCICES in PROLOG



 Exercise 1:

Let's consider the following incomplete program :

mysterious([A|B],C,[A|D]) :- mysterious(B,C,D).

1/ Complete this program such that :
     mysterious(A,B,X) where A = [a,b] and B = [z] will hold (is true).

2/  Develop the derivation tree for the goal :
           ?- mysterious([a,b],[z],X).

3/ What is the role of the prediate mysterious ?
 

Exercise 2 :

 Write the predicate adjacent(E1,E2,L) which is true if the elements E1
and E2 are adjacents
(in this order) in a given list.

 Exp :
          adjacent(a,b,[x,y,a,b,c]) ---> true
          adjacent(a,b.[x,y,a,c,d]) ----> false
          adjacent(a,b,[x,y,b,a,c]) -----> false
 

Exercise 3 :

 Write a predicate traduce(Lo,Lt) where Lo is a list of digits and Lt
the
list of the corresponding words.

Exp :  traduce([1,3,5],L) ----> L =  [one, two, three].

Exercise 4 :

  Write a predicate insert(E,N,Lo,Lr) which inserts the element E in the
list Lo at the position
N. Lr will contain the corresponding result.

 Exp :  insert(x,3,[a,b,c,d],L) --->  L = [a,b,x,c,d]



Please report any problems on this webpage to mouhoub@cs.uleth.ca.