~deciduously/aoc2020

65a8579f6aaa415837393ed851ecece12e9a6a89 — Ben Lovy 1 year, 6 months ago d25bcf2
Fix day 4 part 2
1 files changed, 10 insertions(+), 4 deletions(-)

M day4.nim
M day4.nim => day4.nim +10 -4
@@ 62,16 62,22 @@ proc validateEyr(str: Option[string]): bool =
    i >= 2020 and i <= 2030

proc validateHgt(str: Option[string]): bool =
    str.isSome and match(str.get(), re"[0-9]+(in|cm)")
    if str.isSome and match(str.get(), re"^[0-9]+(in|cm)$"):
        let s = str.get()
        let n = parseInt(s[0..^3])
        if s[^2..^1] == "cm":
            return (n >= 150 and n <= 193)
        else:
            return (n >= 59 and n <= 76)

proc validateHcl(str: Option[string]): bool =
    str.isSome and match(str.get(), re"#[0-9a-f]{6}")
    str.isSome and match(str.get(), re"^#[0-9a-f]{6}$")

proc validateEcl(str: Option[string]): bool =
    str.isSome and match(str.get(), re"(amb|blu|brn|gry|grn|hzl|oth)")
    str.isSome and match(str.get(), re"^(amb|blu|brn|gry|grn|hzl|oth)$")

proc validatePid(str: Option[string]): bool =
    str.isSome and match(str.get(), re"[0-9]{9}")
    str.isSome and match(str.get(), re"^[0-9]{9}$")

proc isValidPartTwo(p: Passport): bool =
    validateByr(p.byr) and validateIyr(p.iyr) and