2020-12-05 09:53:27 +01:00
|
|
|
module AoC where
|
|
|
|
|
2020-12-06 07:36:19 +01:00
|
|
|
import Data.Function (on)
|
|
|
|
import Data.List (groupBy, intercalate)
|
2020-12-05 10:21:09 +01:00
|
|
|
import Text.ParserCombinators.ReadP
|
|
|
|
|
2020-12-05 09:53:27 +01:00
|
|
|
(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
|
|
|
|
f .: g = (f .) . g
|
|
|
|
infixl 8 .:
|
|
|
|
|
2020-12-05 10:21:09 +01:00
|
|
|
oneCompleteResult :: ReadP a -> String -> Maybe a
|
|
|
|
oneCompleteResult p s = case readP_to_S (p <* eof) s of
|
|
|
|
[(x, "")] -> Just x
|
|
|
|
_ -> Nothing
|
|
|
|
|
2020-12-06 07:36:45 +01:00
|
|
|
splitOnEmptyLines :: String -> [[String]]
|
|
|
|
splitOnEmptyLines = filter (not . any null) . groupBy ((==) `on` null) . lines
|
2020-12-06 07:36:19 +01:00
|
|
|
|
2020-12-05 09:53:27 +01:00
|
|
|
runAoC :: (Show r1, Show r2) => (String -> i) -> (i -> r1) -> (i -> r2) -> IO ()
|
|
|
|
runAoC inputTransform part1 part2 = do
|
|
|
|
contents <- inputTransform <$> getContents
|
|
|
|
print $ part1 contents
|
|
|
|
print $ part2 contents
|