Find the sum of all the primes below two million.

removeIf :: (a -> Bool) -> [a] -> [a] removeIf p = filter (not . p) sieveIter :: Integral a => [a] -> [a] -> [a] sieveIter [] (x:xs) = x:xs sieveIter (x:xs) acc | x^2 > last (x:xs) = reverse acc++(x:xs) | otherwise = sieveIter xss (x:acc) where xss = removeIf (\n -> n `mod` x == 0) xs primeList :: Integral a => [a] -> [a] primeList xs = sieveIter xs [] pL :: [Integer] pL = primeList [2..2000000] f :: Integer f = sum (takeWhile (< 2000000) pL)

— colorized by palette fm

— Me@2023-02-25 12:35:57 PM

.

.

2023.02.26 Sunday (c) All rights reserved by ACHK

You must be logged in to post a comment.