advent-of-code/three.hs

16 lines
351 B
Haskell

splitlist :: [a] -> ([a],[a])
splitlist list = (take n list,drop n list)
where n = (length list) `div` 2
inBoth :: (Eq a) => ([a],[a]) -> [a]
inBoth (first,second) = do
inFirst <- first
if (inFirst `elem` second) then return inFirst else []
main = do
input <- readFile "three-input.txt"
print $ map ( inBoth . splitlist ) $ lines input