diff options
author | David Thompson <dthompson2@worcester.edu> | 2014-02-02 20:40:59 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2014-02-02 20:40:59 -0500 |
commit | 695daa2df6cf556d087f859d8cb3ca2f3efec2f9 (patch) | |
tree | d57ffdda5157b95c01db1fc129d9c52f39ca3e7a /problem-10.scm | |
parent | c3b0cff7542d7b643ce9f80ec16a9ea15935dc2e (diff) |
Solve problem 10.
Diffstat (limited to 'problem-10.scm')
-rw-r--r-- | problem-10.scm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/problem-10.scm b/problem-10.scm new file mode 100644 index 0000000..d984831 --- /dev/null +++ b/problem-10.scm @@ -0,0 +1,23 @@ +(use-modules (srfi srfi-1)) + +(define (divisible? m n) + (zero? (modulo m n))) + +(define (prime-sieve n) + (define (mark-multiples! bits x) + (define (mark y) + (when (< y n) + (bitvector-set! bits (1- y) #t) + (mark (+ y x)))) + (mark x)) + (define (sieve m primes bits) + (cond ((= m n) + primes) + ((bitvector-ref bits (1- m)) + (sieve (1+ m) primes bits)) + (else + (mark-multiples! bits m) + (sieve (1+ m) (cons m primes) bits)))) + (sieve 2 '() (make-bitvector n))) + +(reduce + 0 (prime-sieve 2000000)) |