chore: complete day 4

main
sgoudham 2 years ago
parent ba9b283d11
commit c6053d1f89
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -1,16 +1,30 @@
{-# LANGUAGE OverloadedStrings #-}
module Days.Day04 (day04) where module Days.Day04 (day04) where
import AOC (Solution (..)) import AOC (Solution (..))
import qualified Data.Text as T import Data.Text qualified as T
day04 :: Solution day04 :: Solution
day04 = Solution parseInput part1 part2 day04 = Solution parseInput part1 part2
parseInput :: T.Text -> a parseInput :: T.Text -> [[[Int]]]
parseInput = error "parseInput not defined for day 04" parseInput = map (map (map (read . T.unpack) . T.splitOn "-") . T.splitOn ",") . T.lines
part1 :: a -> Int part1 :: [[[Int]]] -> Int
part1 = error "part1 not defined for day 04" part1 input = sum $ map logic input
where
logic [[u1, u2], [d1, d2]]
| u1 >= d1 && u2 <= d2 = 1
| d1 >= u1 && d2 <= u2 = 1
| otherwise = 0
part2 :: a -> Int part2 :: [[[Int]]] -> Int
part2 = error "part2 not defined for day 04" part2 input = sum $ map logic input
where
logic [[u1, u2], [d1, d2]]
| u1 >= d1 && u1 <= d2 = 1
| u2 >= d1 && u2 <= d2 = 1
| d1 >= u1 && d1 <= u2 = 1
| d2 >= u1 && d2 <= u2 = 1
| otherwise = 0

Loading…
Cancel
Save