CSCI 310 Fall 2005 Exam #1

 

Instructions:  This exam is closed book, closed notes, closed neighbor, closed IM, open (hopefully) mind.  Show all your work in the space provided.  If you need more room, use the back of one of the other pages and note where your answer is found.  You have 50 minutes to complete this exam, so read through the entire exam before starting to answer any question in order to plan how best to use your time.  Point values are shown for each question.  Not counting the bonus, there are 100 points possible on this exam.

 

1.       (40 points) Short answer:

a.      Variables in Prolog are easily identified by what characteristic?

 

 

 

 

 

b.      What is the predicate that tests for an empty list in Lisp?

 

 

 

 

 

c.      How, syntactically, do you represent the head and the rest of the list in Prolog?

 

 

 

 

 

d.      What function in Lisp takes the lists (a b) and (c d) and combines them to get the list (a b c d)?

 

 

 

 

 

e.      What operator does Prolog use to compare two numbers to see if one is not equal to the other?

 

 

 

 

 

f.        What function in Lisp takes the lists (a b) and (c d) and combines them to get the list ((a b) (c d))?

 

 

 

 

 

g.      Prolog programs are made up of what two main parts?

 

 

 

 

 

h.     What function in Lisp takes the lists (a b) and (c d) and combines them to get the list ((a b) c d)?

 

 

 

 

 

i.        Write a Prolog statement to represent the knowledge that if someone is a child of someone else, then the second person is parent of the first.

 

 

 

 

 

j.        What function returns the head of a list in Lisp?

 

 

 

 

 

k.      Write a Prolog statement to represent the knowledge that the grass is green.

 

 

 

 

 

l.        In a functional programming language, how does one do looping?

 

 

 

 

 

m.   How would Prolog represent the Lisp list (a b c d)?

 

 

 

 

 

n.     What two languages did Stroustrup draw from to design C++?

 

 

 

 

 

o.      What language was designed by the DoD so that managers could read and understand programs because of the English-like syntax?

 

 

 

 

 

p.      What programming language proved by example the feasibility of using high level programming languages to write efficient computer programs?

 

 

 

 

 

q.      What language was designed by a committee for the DoD to solve its problem of having hundreds of different languages in use in its various weapons systems?

 

 

 

 

 

r.        What language was designed by Sun to allow interoperability of programs across a network running on widely different hardware?

 

 

 

 

 

s.      What language was designed as a teaching language, to make it easy to teach students how to program and to make it easy to build a compiler for it?

 

 

t.        What language sprang from the effort to build intelligent computers, and is still used for artificial intelligence programming today?

 

 

 

 

 

2.      (10 points)  What are the three main categories of programming languages?  Describe the main features of each, and indicate what makes each different from the others.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3.      Lisp programming:

a.      (10 points)  Write a Lisp function that takes a single list as a parameter and returns a copy of the list concatenated with itself.  For instance, if given the list (a b c d), the function would return (a b c d a b c d).

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

b.      (15 points)  Write a Lisp function to compute hailstone numbers.  Your function should take a single number as a parameter and return the number of steps it takes to turn that number into 1 using the formula .  You may use the predicate oddp, which returns true if a number is odd.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4.      Prolog programming:

a.      (10 points)  Represent the following knowledge in Prolog:

·         Fred is the father of Dan and John..

·         Fred, Dan and John are male.

·         Mary is the mother of Dan and John.

·         Mary is female.

·         The parent of someone is either their father or mother.

·         Siblings have the same parents.

·         You are my brother if we have the same parents and if you are male.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

b.      (15 points)  Write a Prolog program that takes a list and reverses it.

 


Bonus: (5 points) You have two slow-burning fuses, each of which will burn up in exactly one hour. They are not necessarily of the same length and width as each other, nor even necessarily of uniform width, so you can't measure a half hour by noting when one fuse is half burned. Using these two fuses, how can you measure 45 minutes?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bonus: (5 points) At McDonald's you can order Chicken McNuggets in boxes of 6, 9, and 20. What is the largest number of nuggets that it is not possible to obtain by purchasing some combination of boxes?