Skip to content

Instantly share code, notes, and snippets.

@Denommus
Created July 31, 2015 13:43
Show Gist options
  • Save Denommus/57f918084bf45089a82e to your computer and use it in GitHub Desktop.
Save Denommus/57f918084bf45089a82e to your computer and use it in GitHub Desktop.
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