Safe Haskell | None |
---|
Day04
Description
General - Mainly a file parsing problem. Parsescan all passports. Whenwhile scanning all fields are optional (might be there or not). While checking only cid is optional (all other fields need to be there).
Question is: What is the right datastructure for this? Could do a Map or a list of key/value pairs or a record with optional fields (Maybe).
Let's go monadic. Let's use Maybe.
Part 1 - Scan the file and do the check.
Part 2 - Scan the file and do the checks (using regexes).
Synopsis
- data Passport = Passport (Maybe String) (Maybe String) (Maybe String) (Maybe String) (Maybe String) (Maybe String) (Maybe String) (Maybe String)
- makePassport :: [(String, String)] -> Passport
- isValid :: Passport -> Bool
- isValid2 :: Passport -> Bool
- isValidBirthYear :: Maybe String -> Bool
- isValidIssueYear :: Maybe String -> Bool
- isValidExpirationYear :: Maybe String -> Bool
- isValidHeight :: Maybe String -> Bool
- isValidHairColor :: Maybe String -> Bool
- isValidEyeColor :: Maybe String -> Bool
- isValidPassportID :: Maybe String -> Bool
- checkFormatted :: String -> String -> Bool
- input :: String -> [Passport]
- part1 :: [Passport] -> Int
- part2 :: [Passport] -> Int
Documentation
The passport (with all its optional fields).
Constructors
Passport (Maybe String) (Maybe String) (Maybe String) (Maybe String) (Maybe String) (Maybe String) (Maybe String) (Maybe String) |
makePassport :: [(String, String)] -> Passport #
Make a passport.
isValidBirthYear :: Maybe String -> Bool #
The rule that makes the birth year valid.
isValidIssueYear :: Maybe String -> Bool #
The rule that makes the issue year valid.
isValidExpirationYear :: Maybe String -> Bool #
The rule that makes the experation year valid.
isValidHeight :: Maybe String -> Bool #
The rule that makes the height valid.
isValidHairColor :: Maybe String -> Bool #
The rule that makes the hair color valid.
isValidEyeColor :: Maybe String -> Bool #
The rule that makes the eye color valid.
isValidPassportID :: Maybe String -> Bool #
The rule that makes the passport id valid.
checkFormatted :: String -> String -> Bool #
Make sure the field is formatted correctly.