Home

About

Advanced Search

Browse by Discipline

Scientific Societies

E-print Alerts

Add E-prints

E-print Network
FAQHELPSITE MAPCONTACT US


  Advanced Search  

 
Program #7 30 points Prolog Programming
 

Summary: Program #7 30 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 or your instructor.

1. (3 points) Drop every N'th element from a list.
Example:
?- drop([a,b,c,d,e,f,g,h,i,k],3,X).
X = [a,b,d,e,g,h,k]
Hint: The arithmetic operators are: =,is,<,>,=<,>=,==,=:=,/,*,+,-,mod,div
To perform arithmetic, use "is" not "=".
I found it useful to create split(L,N,L1,L2) which took list L and split it into two lists, the first of
which is N in length.
Hint: typing "a" aborts the execution.
2. (3 points) Extract a slice from a list.
Given two indices, I and K, the slice is the list containing the elements between the I'th and K'th
element of the original list (both limits included). Start counting the list elements with 1.
Example:

  

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

 

Collections: Computer Technologies and Information Sciences