aoc2022/4-a.hs

18 lines
475 B
Haskell

{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wno-incomplete-patterns #-}
import qualified Data.Text as T
import Data.List
isContained :: [[Int]] -> Bool
isContained [a, b] = intersection == a || intersection == b
where intersection = a `intersect` b
toRange :: [Int] -> [Int]
toRange [a, b] = [a .. b]
main = interact $
show
. length . filter id
. map (isContained . map (toRange . map (read . T.unpack) . T.splitOn "-") . T.splitOn "," . T.pack)
. lines