Created
July 31, 2015 13:43
-
-
Save Denommus/57f918084bf45089a82e to your computer and use it in GitHub Desktop.
Solves this: http://pastebin.com/KMzTHKE4
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
import Control.Monad | |
import Control.Arrow | |
splitListInHalf :: [a] -> ([a], [a]) | |
splitListInHalf = splitAt =<< flip div 2 . (+1) . length | |
checkOneDifferent :: Eq a => [a] -> [a] -> Bool | |
checkOneDifferent a b = 1==(length . filter not . map (uncurry (==)) $ zip a b) | |
transformTuple :: ((a,b),(c,d)) -> ((a,c),(b,d)) | |
transformTuple ((a1,a2),(b1,b2)) = ((a1,b1),(a2,b2)) | |
test :: Eq a => [a] -> [a] -> Bool | |
test = curry $ uncurry (&&) . join (***) (uncurry checkOneDifferent) . transformTuple . join (***) splitListInHalf | |
main :: IO () | |
main = do | |
let a = [0,0,1,1] | |
let b = [0,1,0,1] | |
print $ test a b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment