This commit is contained in:
NaiJi ✨ 2020-08-26 11:32:16 +03:00
parent 75bce812b1
commit f75029f32b
1 changed files with 17 additions and 0 deletions

17
sicp-ex-1.21.rkt Normal file
View File

@ -0,0 +1,17 @@
(define (square n)
(* n n))
(define (smallest-divisor n)
(find-divisor n 2))
(define (find-divisor n test-divisor)
(cond ((> (square test-divisor) n) n)
((divides? test-divisor n) test-divisor)
(else (find-divisor n (+ test-divisor 1)))))
(define (divides? a b)
(= (remainder b a) 0))
(smallest-divisor 199)
(smallest-divisor 1999)
(smallest-divisor 19999)