Home

About

Advanced Search

Browse by Discipline

Scientific Societies

E-print Alerts

Add E-prints

E-print Network
FAQHELPSITE MAPCONTACT US


  Advanced Search  

 
Program #6 20 points Prolog Programming
 

Summary: Program #6 20 points
Prolog Programming

Don't show your code to anyone in the class. Don't read anyone else's code. Do not
google to find complete solutions to the exercises (as that involves reading someone else's
code). Don't discuss the details of your code with anyone except the tutors, grader, or your
instructor.


A list is either empty or it is composed of a first element (head) and a tail, which is a list
itself. In Prolog we represent the empty list by the atom [] and a non-empty list by a term [H|T]
where H denotes the head and T denotes the tail.
1. (2 points) Find the last element of a list.
Example:
?- my_last(X,[a,b,c,d]).
X = d
2. (2 points) Find the K'th element of a list.
The first element in the list is number 1.
Example:
?- element_at(X,[a,b,c,d,e],3).

  

Source: Allan, Vicki H. - Department of Computer Science, Utah State University

 

Collections: Computer Technologies and Information Sciences