close to solution for part 1
This commit is contained in:
parent
26d15c0640
commit
5e96cc43b6
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user