22 lines
472 B
Racket
Executable File
22 lines
472 B
Racket
Executable File
(define (square n)
|
|
(* n n))
|
|
|
|
(define (smallest-divisor n)
|
|
(find-divisor n 2))
|
|
|
|
(define (find-divisor n test-divisor)
|
|
(define (next iterator)
|
|
(if (= iterator 2) 3 (+ iterator 2)))
|
|
|
|
(cond ((> (square test-divisor) n) n)
|
|
((divides? test-divisor n) test-divisor)
|
|
(else (find-divisor n (next test-divisor)))))
|
|
; find-divisor
|
|
|
|
(define (divides? a b)
|
|
(= (remainder b a) 0))
|
|
|
|
(smallest-divisor 199)
|
|
(smallest-divisor 1999)
|
|
(smallest-divisor 19999)
|