Legendre prime counting function: Difference between revisions
Content added Content deleted
GordonBGood (talk | contribs) m (put Java contribution in alphabetic order...) |
GordonBGood (talk | contribs) m (→Non Memoized Haskell Versions: Haskell: improve comments...) |
||
Line 1,370: | Line 1,370: | ||
'''The Non-Recursive Partial Sieving Algorithm''' |
'''The Non-Recursive Partial Sieving Algorithm''' |
||
Just substitute the following Haskell code for the `countPrimes` function above to enjoy the further gain in speed: |
Just substitute the following Haskell code for the `countPrimes` function above to enjoy the further gain in speed; this version may appear to be recursive to those unfamiliar with Functional Programming (FP) implementations but FP generally turns all function recursions in tail-call position (which all of these are) into the same compiled code as a simple loop in other languages: |
||
<syntaxhighlight lang="haskell"> |
<syntaxhighlight lang="haskell">countPrimes :: Word64 -> Int64 |
||
countPrimes n = |
|||
if n < 3 then (if n < 2 then 0 else 1) else |
if n < 3 then (if n < 2 then 0 else 1) else |
||
let |
let |