29 lines
904 B
Haskell
29 lines
904 B
Haskell
{-# LANGUAGE ScopedTypeVariables #-}
|
|
import Data.Char
|
|
import Data.List.Split
|
|
import Data.List
|
|
import Data.Maybe
|
|
|
|
main = do
|
|
ls <- readFile "4.in"
|
|
putStrLn . show . solveB . parse$ ls
|
|
where
|
|
solveA :: [[[Int]]] -> Int
|
|
solveA = length . filter id . map contains
|
|
|
|
solveB :: [[[Int]]] -> Int
|
|
solveB = length . filter id . map overlaps
|
|
|
|
parse :: String -> [[[Int]]]
|
|
parse = map ( map (map parseInt . splitOn "-") . splitOn ",") .lines where
|
|
parseInt = read :: String -> Int
|
|
|
|
contains :: Ord a => [[a]] -> Bool
|
|
contains [[a,b],[c,d]] = isSorted [a, c, d, b] || isSorted [c, a, b, d]
|
|
|
|
overlaps :: Ord a => [[a]] -> Bool
|
|
overlaps [[a,b],[c,d]] = isSorted [a,c,b] || isSorted [a,d,b] || isSorted [c, a, d] || isSorted [c, b, d]
|
|
|
|
isSorted :: Ord a => [a] -> Bool
|
|
isSorted x = x == sort x
|