Advertisement
banovski

Project Euler, Problem #10, Haskell

Feb 11th, 2022 (edited)
1,313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- The task: the sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
  2. -- Find the sum of all the primes below two million.
  3.  
  4. primeCheck :: Int -> Bool
  5. primeCheck x =
  6.   null [y | y <- [3,5 .. (ceiling . sqrt . fromIntegral) x], mod x y == 0]
  7.  
  8. primes :: [Int]
  9. primes = filter primeCheck [1999999,1999997 .. 9]
  10.  
  11. main :: IO ()
  12. main = print $ sum (17 : primes)
  13.  
  14. -- 142913828922
  15.  
  16. -- real 0m9,724s
  17. -- user 0m9,620s
  18. -- sys  0m0,092s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement