diff --git a/day02/lib/Day02.hs b/day02/lib/Day02.hs index cb4aa2c..3b58c26 100644 --- a/day02/lib/Day02.hs +++ b/day02/lib/Day02.hs @@ -1,2 +1,29 @@ module Day02 where +import Data.Maybe (fromMaybe) +import Text.Read (readMaybe) + +data Move = Horizontal Int | Depth Int deriving Show + +readDataLines:: (String -> Maybe a) -> String -> Either String [a] +readDataLines f s = case mapM f (lines s) of + Just xs -> Right xs + Nothing -> Left "Error parsing string" + +day02Part1 :: String -> String +day02Part1 _ = "Day02 Part1" + + +day02Part2 :: String -> String +day02Part2 _ = "Day02 Part2" + +readDirection ::String -> Maybe (Int -> Move) +readDirection "forward" = Just Horizontal +readDirection "down" = Just Depth +readDirection "up" = Just (Depth . negate) +readDirection _ = Nothing + +readMove :: String -> Maybe Move +readMove s = case words s of + [dirStr, distStr] -> readDirection dirStr <*> readMaybe distStr + _ -> Nothing