day 4
This commit is contained in:
parent
aa92e0c644
commit
63aec0f907
|
|
@ -0,0 +1,24 @@
|
|||
import Data.List.Split (splitOn)
|
||||
|
||||
type Quad = ((Int, Int), (Int, Int))
|
||||
|
||||
parseQuad :: String -> Quad
|
||||
parseQuad s = (parsePair a, parsePair b) where
|
||||
[a,b] = splitOn "," s
|
||||
parsePair s = let [x,y] = splitOn "-" s in (read x, read y)
|
||||
|
||||
part1 :: Quad -> Bool
|
||||
part1 ((a,b), (x,y)) = (a <= x && b >= y) || (x <= a && y >= b)
|
||||
|
||||
part2 :: Quad -> Bool
|
||||
part2 ((a,b), (x,y)) = (a <= x && b >= x) || (x <= a && y >= a)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
x <- map parseQuad . lines <$> getContents
|
||||
|
||||
putStr "part 1: "
|
||||
print $ length (filter part1 x)
|
||||
|
||||
putStr "part 2: "
|
||||
print $ length (filter part2 x)
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,6 @@
|
|||
2-4,6-8
|
||||
2-3,4-5
|
||||
5-7,7-9
|
||||
2-8,3-7
|
||||
6-6,4-6
|
||||
2-6,4-8
|
||||
Loading…
Reference in New Issue