Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.List
- import Data.Ord
- isPrime :: Integer -> Bool
- primes :: Integer ->[Integer]
- isLengthLessThan :: Int -> [a] -> Bool
- isLengthLessThan 0 _ = False
- isLengthLessThan _ [] = True
- isLengthLessThan n (_:ys) = isLengthLessThan (n-1) ys
- isPrime x
- | x == 2 = True
- | mod x 2 == 0 = False
- | otherwise = isLengthLessThan 2 [y | y <- [1,3.. roof], mod x y == 0]
- where roof = 1 + truncate (sqrt $fromIntegral x)
- primes x
- | isPrime x = [x]
- | otherwise = factor : primes(div x factor)
- where factor = head $filter checkdiv [2..]
- checkdiv n = x `mod` n == 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement