From 2de1f283bd325b2108efe4fbc3122f754f300b55 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Wed, 10 Nov 2021 10:57:16 +0300 Subject: [PATCH] feat(haskell): add prime number --- haskell/8_prime_number.hs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 haskell/8_prime_number.hs diff --git a/haskell/8_prime_number.hs b/haskell/8_prime_number.hs new file mode 100644 index 0000000..29849ae --- /dev/null +++ b/haskell/8_prime_number.hs @@ -0,0 +1,8 @@ +module IsPrime where + +isPrime :: Integer -> Bool +isPrime x + | x `elem` [2, 3, 5, 7] = True + | x < 2 || even x = False + | otherwise = not $ any (\n -> x `rem` n == 0) [3, 5..last] + where last = (round . sqrt . fromIntegral) x