AoC/2022/day04/day04.hs

22 lines
522 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
testEnclave :: [[Int]] -> Bool
testEnclave (x:y:[]) = a == x || a == y
where a = x `intersect` y
day4a :: [[[Int]]] -> Int
day4a = sum . map (fromEnum . testEnclave)
day4b :: [[[Int]]] -> Int
day4b = sum . map (fromEnum . not . null . foldl1 intersect)