Skip to content

Instantly share code, notes, and snippets.

Last active May 12, 2018
What would you like to do?
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