The sieve of Sundaram: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Added a functional variant.)
Line 511: Line 511:
from math import floor, log, sqrt
from math import floor, log, sqrt
from itertools import islice
from itertools import islice


# nPrimesBySundaram :: Int -> [Int]
def nPrimesBySundaram(n):
'''First n primes, by sieve of Sundaram.
'''
return list(islice(
sundaram(
# Probable limit
int((2.4 * n * log(n)) // 2)
),
int(n)
))




Line 541: Line 528:
if not x in exclusions
if not x in exclusions
]
]


# nPrimesBySundaram :: Int -> [Int]
def nPrimesBySundaram(n):
'''First n primes, by sieve of Sundaram.
'''
return list(islice(
sundaram(
# Probable limit
int((2.4 * n * log(n)) // 2)
),
int(n)
))