16 lines
331 B
Plaintext
16 lines
331 B
Plaintext
(defn smallest-divisor [n]
|
|
(defn square [n]
|
|
(* n n))
|
|
(defn divides? [a b]
|
|
(= (mod b a) 0))
|
|
(defn iter [n test]
|
|
(cond
|
|
(> (square test) n) n
|
|
(divides? test n) test
|
|
(iter n (+ test 1))))
|
|
(iter n 2))
|
|
|
|
(trace (smallest-divisor 199))
|
|
(print (smallest-divisor 1999))
|
|
(print (smallest-divisor 19999))
|