day4
This commit is contained in:
parent
d9b902d551
commit
dbbf23bcd1
21
2022/day04/day04.hs
Normal file
21
2022/day04/day04.hs
Normal file
@ -0,0 +1,21 @@
|
||||
import Data.List.Split
|
||||
import Data.List
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
input <- parse <$> readFile "input"
|
||||
print $ day4a input
|
||||
print $ day4b input
|
||||
|
||||
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)
|
||||
|
||||
day4b :: [[[Int]]] -> Int
|
||||
day4b = sum . map (fromEnum . not . null . foldl1 intersect)
|
1000
2022/day04/input
Normal file
1000
2022/day04/input
Normal file
File diff suppressed because it is too large
Load Diff
6
2022/day04/testinput
Normal file
6
2022/day04/testinput
Normal 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
|
Loading…
Reference in New Issue
Block a user