From afd4ca3dc33cebcd4fff0318fd362d3c362e1d07 Mon Sep 17 00:00:00 2001 From: Sloane Perrault Date: Sun, 4 Dec 2022 09:40:05 -0500 Subject: [PATCH] dry up 2022 day 4 --- 2022/src/Aoc/Day4.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/2022/src/Aoc/Day4.hs b/2022/src/Aoc/Day4.hs index 6bf53ef..015d177 100644 --- a/2022/src/Aoc/Day4.hs +++ b/2022/src/Aoc/Day4.hs @@ -42,9 +42,11 @@ overlap ((a, b), (c, d)) | d < a = False -- first is fully to the right of second | otherwise = True -- there's some overlap -solve :: Integer -> String -> Integer -solve 1 input = fromIntegral $ length $ filter fullOverlap $ parse input +solve' :: String -> (Row -> Bool) -> Integer +solve' input predicate = fromIntegral $ length $ filter predicate $ parse input -solve 2 input = fromIntegral $ length $ filter overlap $ parse input +solve :: Integer -> String -> Integer +solve 1 input = solve' input fullOverlap +solve 2 input = solve' input overlap solve _ _ = 0