import qualified Data.Map.Strict as M import Text.ParserCombinators.ReadP import Control.Applicative ((<|>)) main :: IO () main = do shifts <- map parse . lines <$> getContents print "a" type GID = Int data Status = Begin | Awake | Asleep deriving (Show) data Date = Date Int Int Int deriving (Show) data Time = Time Int Int deriving (Show) data Shift = Shift Status GID Date Time deriving (Show) parse :: String -> Shift parse = fst . head . readP_to_S go where digit :: ReadP Char digit = satisfy (\char -> char >= '0' && char <= '9') stGet :: String -> Status stGet "wakes up" = Awake stGet "falls asleep" = Asleep stGet "Guard #" = Begin go :: ReadP Shift go = do char '[' year <- read <$> count 4 digit char '-' month <- read <$> count 2 digit char '-' day <- read <$> count 2 digit char ' ' hour <- read <$> count 2 digit char ':' minute <- read <$> count 2 digit string "] " rt <- string "Guard #" <|> string "wakes up" <|> string "falls asleep" gid <- option (-1) (read <$> many1 digit) optional $ string " begins shift" eof let d = Date year month day let t = Time hour minute return (Shift (stGet rt) gid d t)