AoC/2022/day04/day04.hs

18 lines
452 B
Haskell
Raw Normal View History

2022-12-04 15:08:44 +01:00
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
2022-12-04 15:42:36 +01:00
day4a = sum . map (fromEnum . (\[x,y] -> x `isInfixOf` y) . sortOn length)
2022-12-04 15:08:44 +01:00
day4b :: [[[Int]]] -> Int
day4b = sum . map (fromEnum . not . null . foldl1 intersect)