asb: head /dev/brain > /dev/www

My home, musings, and wanderings on the world wide web.

99 LISP problems: Problem #31

Solution to the 99 LISP Problems #31

1
2
3
4
5
6
7
8
9
10
11
12
13
(defun range (lo hi)
  (cond ((> lo hi) nil)
        (t (cons lo (range (1+ lo) hi)))))

(defun all (alist)
  (cond ((null alist) t)
        (t (and (car alist)
                (all (cdr alist))))))

(defun primep (n)
  (all (mapcar
         (lambda (x) (not (= 0 (mod n x))))
         (range 2 (isqrt n)))))

Lisp dialect: Steel Bank Common Lisp