feat(haskell): add prime number
This commit is contained in:
parent
92e07981cf
commit
2de1f283bd
1 changed files with 8 additions and 0 deletions
8
haskell/8_prime_number.hs
Normal file
8
haskell/8_prime_number.hs
Normal file
|
@ -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
|
Loading…
Reference in a new issue