Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fastSolve :: [Int] -> Bool
- fastSolve xs = interpret (accSolve Nothing Nothing Nothing Nothing xs)
- rEven, rOdd, rSmall :: Int -> Bool
- rEven x = x `mod` 2 == 0
- rOdd x = x > 0 && x `mod` 2 == 1
- rSmall x = 5 <= x && x <= 10
- -- shortcut for types
- type M a = Maybe a
- accSolve :: M Int -> M Int -> M Int -> M Int -> [Int] -> (M Int, M Int, M Int, M Int)
- accSolve sE sO bE bO [] = (sE,sO,bE,bO)
- accSolve sE sO bE bO (x:xs) = case (rSmall x, rEven x, rOdd x) of
- (True, True, False) -> case sE of
- Nothing -> accSolve (Just x) sO bE bO xs
- (Just y) -> accSolve sE sO (Just x) bO xs
- (True, False, True) -> case sO of
- Nothing -> accSolve sE (Just x) bE bO xs
- (Just y) -> accSolve sE sO bE (Just x) xs
- (False, True, False) -> accSolve sE sO (Just x) bO xs
- (False, False, True) -> accSolve sE sO bE (Just x) xs
- (False, False, False) -> accSolve sE sO bE bO xs
- interpret :: (M Int , M Int , M Int , M Int ) -> Bool
- interpret (Just jsE, _ , Just jbE, Just jbO) = True
- interpret (_ , Just jsO, Just jbE, Just jbO) = True
- interpret (Just jsE, Just jsO, _ , Just jbO) = True
- interpret (Just jsE, Just jsO, Just jbE, _ ) = True
- interpret (_ , _ , _ , _ ) = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement