Last active
May 12, 2018 08:01
-
-
Save yen3/3bd457b2be870a7ff8eb114285dff0a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
goldbach :: Int -> Maybe (Int, Int) | |
goldbach n = let ps = [(x, n-x) | x <- [2..(n `div` 2)], isPrime x, isPrime (n-x)] | |
in safeFst ps | |
where isPrime n = and (map (\x -> n `mod` x /= 0) [2..(n-1)]) | |
safeFst [] = Nothing | |
safeFst (x:xs) = Just x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment