(define (prime)
(define (prime-loop n pr)
(define (p? i p)
(if (= (length p) 0)
#t
(if (= (remainder i (car p)) 0)
#f
(p? i (cdr p)))))
(if (<= n 1000)
(prime-loop (+ n 1)
(if (p? n pr)
(append pr (list n))
pr))
pr))
(prime-loop 2 '()))
You write a faster program if you use Sieve of Eratosthenes.
Sieve of Eratosthenes - Wikipedia, the free encyclopedia
No comments:
Post a Comment