import Data.List
import Data.List.Split

main :: IO ()
main = do
  input <- parse <$> readFile "input"
  print $ day4a input
  print $ day4b input

parse :: String -> [[[Int]]]
parse = map (map ((\[x,y]->[read x .. read y]) . splitOn "-") . splitOn ",") . lines

day4a :: [[[Int]]] -> Int
day4a = sum . map (fromEnum . (\[x,y] -> x `isInfixOf` y) . sortOn length)

day4b :: [[[Int]]] -> Int
day4b = sum . map (fromEnum . not . null . foldl1 intersect)
