module Solutions.P75 (maybeGoldbach) where
import Control.Monad (guard)
import Solutions.P40 (goldbach)
import Text.Read (readMaybe)
maybeGoldbach :: String -> Maybe (Integer, (Integer, Integer))
maybeGoldbach :: String -> Maybe (Integer, (Integer, Integer))
maybeGoldbach String
s = do
Integer
n <- String -> Maybe Integer
forall a. Read a => String -> Maybe a
readMaybe String
s
Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Integer
2
Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Integer -> Bool
forall a. Integral a => a -> Bool
even Integer
n
(Integer, (Integer, Integer))
-> Maybe (Integer, (Integer, Integer))
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer
n, Integer -> (Integer, Integer)
forall a. Integral a => a -> (a, a)
goldbach Integer
n)