@@ 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