Skip to main content
3 of 3
Added another solution

I am not a complete expert in CL but would like to give some advice, which you might find helpful.

General style

You should not leave closing parenthesis on a extra line. See e.g. here for some remarks on style. Furthermore, a documentation string would help others and yourself in the future to understand your code.

Performance

I haven't reviewed my own solution of this problem but I guess specifying fixnum instead of integer will lead to another factor of 2 in performance and should be possible for this problem.

Loop

You could write has-all-divisors more idiomatic using loops always clause:

(defun has-all-divisors (num start stop) (declare (type fixnum num start stop)) (loop for divisor of-type fixnum from start to stop always (divides-even-p num divisor))) 

Alternative solution

If I remember this problem correctly, you could use another algorithm which should be way faster. Collect all prime factors of the integers from 2 to 20 and build their product.