mykatas/haskell/8_prime_number.hs

9 lines
229 B
Haskell
Raw Normal View History

2021-11-10 10:57:16 +03:00
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