Sha256: 4ae3334161da2048e24ae9f66821e83943d9ba152c7f23de495150d14b7ee5e5
Contents?: true
Size: 825 Bytes
Versions: 96
Compression:
Stored size: 825 Bytes
Contents
(defpackage #:sieve (:use #:cl) (:export #:primes-to) (:documentation "Generates a list of primes up to a given limit.")) (in-package #:sieve) (defun primes-to (n) "List primes up to `n' using sieve of Eratosthenes." (loop initially (when (< n 2) (return nil)) with sqrtn = (1+ (isqrt n)) with sieve = (make-array (1+ n) :element-type 'boolean :initial-element t) for maybe from 2 to sqrtn when (aref sieve maybe) do (loop for multi from (* maybe maybe) upto n by maybe when (aref sieve multi) do (setf (aref sieve multi) nil)) finally (return (loop for index from 2 upto n when (aref sieve index) collect index))))
Version data entries
96 entries across 96 versions & 1 rubygems