AoC/2022/day04/day04.hs
2022-12-04 15:42:36 +01:00

18 lines
452 B
Haskell

import Data.List.Split
import Data.List
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)