Skip to content

Instantly share code, notes, and snippets.

@yen3
Last active May 12, 2018 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yen3/3bd457b2be870a7ff8eb114285dff0a5 to your computer and use it in GitHub Desktop.
Save yen3/3bd457b2be870a7ff8eb114285dff0a5 to your computer and use it in GitHub Desktop.
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