Created
February 28, 2018 01:03
-
-
Save justinmeiners/b42f717c5a315a68c6ca82c11eeb12c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (prime-sieve count) | |
(let ((marked (make-vector count #f))) | |
(define (build-list index) | |
(if (>= index count) | |
'() | |
(if (vector-ref marked index) | |
(build-list (+ index 1)) | |
(cons (+ index 1) (build-list (+ index 1)))))) | |
(define (next-prime index) | |
(if (>= index count) | |
marked | |
(begin | |
(if (vector-ref marked index) | |
'done | |
(mark (+ index 1) (+ index index 1))) | |
(next-prime (+ index 1))))) | |
(define (mark stride index) | |
(if (>= index count) | |
'ok | |
(begin | |
(vector-set! marked index #t) | |
(mark stride (+ index stride))))) | |
(begin (next-prime 1) (build-list 1)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment