This commit is contained in:
NaiJi ✨ 2020-09-01 18:01:47 +03:00
parent f75029f32b
commit a092c7f670
1 changed files with 21 additions and 0 deletions

21
sicp-ex-1.23.rkt Normal file
View File

@ -0,0 +1,21 @@
(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)