This commit is contained in:
Quinten Kock 2022-12-04 15:37:22 +01:00
parent aa92e0c644
commit 63aec0f907
3 changed files with 1030 additions and 0 deletions

24
2022/day04.hs Normal file
View File

@ -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)

1000
2022/inputs/day04 Normal file

File diff suppressed because it is too large Load Diff

6
2022/inputs/day04.test Normal file
View File

@ -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