SCIP 1.21

Use the smallest-divisor procedure to find the smallest divisor of each of the
following numbers: 199, 1999, 19999.

(defun squre(x)
  (* x x))


(defun even?(x)
  (= (mod x 2) 0))


(defun doublef(x)
  (+ x x))


(defun half(x)
  (/ x 2))



(defun smallest-divisor (n)
  (find-divisor n 2))

(defun find-divisor(n test-divisor)
  (cond ((> (squre test-divisor) n) n )
	(( divides? test-divisor n) test-divisor)
	( (find-divisor n (+ test-divisor 1)))))


(defun divides? (a b)
  (= (mod b a) 0))


(defun prime? (n)
    (= n (smallest-divisor n)))


CL-USER> (smallest-divisor 199)
199
CL-USER> (smallest-divisor 1999)
1999
CL-USER> (smallest-divisor 19999)
7

  
Edit in Emacs with Slime and Steel Bank Common Lisp.