-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay4.hs
More file actions
27 lines (20 loc) · 666 Bytes
/
Copy pathDay4.hs
File metadata and controls
27 lines (20 loc) · 666 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Day4
( part1
, part2
) where
import Data.List.Split (splitOn)
day = 4
overlapFull :: ((Int, Int), (Int, Int)) -> Bool
overlapFull ((a, b), (c, d)) = (a <= c && b >= d) || (c <= a && d >= b)
overlapPart :: ((Int, Int), (Int, Int)) -> Bool
overlapPart ((a, b), (c, d)) = not (c > b || d < a)
pairs :: String -> [((Int, Int), (Int, Int))]
pairs =
map
((\(x:y:_) -> (x, y)) .
map ((\(x:y:_) -> (read x, read y)) . splitOn "-") . splitOn ",") .
lines
part1 :: Bool -> String -> String
part1 _ = show . length . filter overlapFull . pairs
part2 :: Bool -> String -> String
part2 _ = show . length . filter overlapPart . pairs