CSCE 476/876, Spring 2002

Alternative to Homework 3


Here are some Lisp exercises (porbably) more exciting than the ARA..

The terminaloggy (i.e., dot, cross, Cartesian product) is *not* a strict one.

1. (15 points) Borrowed from Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp, Peter Norvig.
    Write a function that takes two vectors of equal lengths given as lists of numbers and generates the dot product:

(d-product '(1 2 4 5) '(3 4 3 4))
returns 43


2. (25 points) Borrowed from Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp, Peter Norvig.
    Write a function that takes a function name and two lists and returns the cross product:

(x-product #'+ '(1 2 3) '(10 20 30))
returns (11 12 13 21 22 23 31 32 33)
and
(x-product #'list '(1 2 3) '(a b c))
 returns ((1 A) (2 A) (3 A) (1 B) (2 B) (3 B) (1 C) (2 C) (3 C))


3. (60 points) Write a function that takes a list of *any* number of lists and return the Cartesian products:

(k-product '((a b c) (1 2 3))) returns:
((A 1) (A 2) (A 3) (B 1) (B 2) (B 3) (C 1) (C 2) (C 3))

(k-product '((a b ) (1 2 3) (x y ))) returns:
((A 1 X) (A 1 Y) (A 2 X) (A 2 Y) (A 3 X) (A 3 Y) (B 1 X) (B 1 Y) (B 2 X) (B 2 Y) (B 3 X) (B 3 Y))


I *may* give bonus to the person that returns the most efficient version of the K-product.  Use the Lisp function "time" to evaluate
the cost of your code.  *If* I do, I'll compile your file and give it a large input to compare with another colleague.  So you may want to
make sure to do the right DECLARATIONS for optimizing your code for speed (check a Lisp manual), etc.

Best wishes,
 


Berthe Y. Choueiry

 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Last modified: