The sieve of Sundaram: Difference between revisions
m
→Python :: Functional
(→{{header|Python}}: Added a functional variant.) |
|||
Line 511:
from math import floor, log, sqrt
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 ⟶ 528:
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)
▲ ))
|