Last active
December 11, 2015 02:48
-
-
Save cky/4532978 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes
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
#lang racket | |
(define (primes-less-than n) | |
(define size (sub1 (quotient n 2))) | |
(define table (build-vector size (lambda (i) (+ i i 3)))) | |
(for ((x (in-vector table 0 (integer-sqrt size))) | |
#:when x | |
(y (in-range (quotient (- (* x x) 3) 2) size x))) | |
(vector-set! table y #f)) | |
(cons 2 (filter values (vector->list table)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment