Jump to content

Legendre prime counting function: Difference between revisions

m
→‎Non Memoized Haskell Versions: Haskell: improve comments...
m (put Java contribution in alphabetic order...)
m (→‎Non Memoized Haskell Versions: Haskell: improve comments...)
Line 1,370:
'''The Non-Recursive Partial Sieving Algorithm'''
 
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">countPrimesxxcountPrimes :: Word64 -> Int64
countPrimesxxcountPrimes n =
if n < 3 then (if n < 2 then 0 else 1) else
let
474

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.