[SOLVED] CS (define (sieve n)

$25

File Name: CS_(define_(sieve_n).zip
File Size: 188.4 KB

5/5 - (1 vote)

(define (sieve n)
(define (iter i primes)
(cond ((= (length primes) n) primes)
((divisBy primes i) (iter (+ i 1) primes))
(else (iter (+ i 1)(append primes (list i))))))
(define (divisBy l i)
(not (= (length (filter l (lambda (x) (= (modulo i x) 0)))) 0)))
(define (filter lis pred)
(cond ((null? lis) lis)
((pred (car lis)) (cons (car lis)(filter (cdr lis) pred)))
(else (filter (cdr lis) pred))))
(iter 2 ()))

(sieve 5)

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS (define (sieve n)
$25