feat(haskell): add prime number

This commit is contained in:
Dmitriy Pleshevskiy 2021-11-10 10:57:16 +03:00
parent 92e07981cf
commit 2de1f283bd
1 changed files with 8 additions and 0 deletions

View 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