[ create a new paste ] login | about

Project: programmingpraxis
Link: http://programmingpraxis.codepad.org/h0U9O7ww    [ raw code | output | fork ]

programmingpraxis - Scheme, pasted on Mar 28:
1
2
3
4
5
6
7
8
9
10
11
12
13
; one million hits

(define (eratosthenes n)
  (let ((sieve (make-vector (+ n 1) #t)))
    (let loop ((p 2) (ps (list)))
      (cond ((< n p) (reverse ps))
            ((vector-ref sieve p)
              (do ((i (* p p) (+ i p))) ((< n i))
                (vector-set! sieve i #f))
              (loop (+ p 1) (cons p ps)))
            (else (loop (+ p 1) ps))))))

(display (length (eratosthenes 15485863)))


Output:
1
Timeout


Create a new paste based on this one


Comments: