Safe HaskellNone

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

Documentation

data Passport #

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) 

Instances

Instances details
Eq Passport # 
Instance details

Defined in Day04

Methods

(==) :: Passport -> Passport -> Bool

(/=) :: Passport -> Passport -> Bool

Show Passport # 
Instance details

Defined in Day04

Methods

showsPrec :: Int -> Passport -> ShowS

show :: Passport -> String

showList :: [Passport] -> ShowS

makePassport :: [(String, String)] -> Passport #

Make a passport.

isValid :: Passport -> Bool #

The rule(s) that make the passport valid (part1).

isValid2 :: Passport -> Bool #

The rules that make the passport valid (part2).

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.

input :: String -> [Passport] #

part1 :: [Passport] -> Int #

Solve part1.

part2 :: [Passport] -> Int #

Solve part2.