day4: dont reimplement infixOf lol

This commit is contained in:
Gattix 2022-12-04 15:42:36 +01:00
parent dbbf23bcd1
commit c6f6bd0af2

@ -10,12 +10,8 @@ main = do
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)
day4a = sum . map (fromEnum . (\[x,y] -> x `isInfixOf` y) . sortOn length)
day4b :: [[[Int]]] -> Int
day4b = sum . map (fromEnum . not . null . foldl1 intersect)