blob: 0772cdcf90323fb2f397eda2152a27cdd7c213aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
(define (prime? n)
(define (smallest-divisor n)
(find-divisor n 2))
(define (find-divisor n test)
(cond ((> (square test) n) n)
((divides? test n) test)
(else (find-divisor n (+ test 1)))))
(define (divides? a b)
(= (remainder b a) 0))
(define (square n)
(* n n))
(= n (smallest-divisor n)))
(define count 0)
(define (display-prime n)
(display n)
(display ", ")
(cond ((> count 8) (display "\n") (let count 0))
(else (define count (+ count 1)))))
(define (primes n limit)
(if (prime? n)
(display-prime n) )
(if (< n limit)
(primes (+ n 1) limit)) )
(primes 3 5000)
|