Fix "off-by-one"

This commit is contained in:
Daniel Flanagan 2020-12-04 09:35:04 -06:00
parent 362946896b
commit 5277507ede
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4

View file

@ -13,7 +13,7 @@ let nonDecimal = re"[^0-9]"
let hgt = re"\d+(cm|in)" let hgt = re"\d+(cm|in)"
let hcl = re"#[0-9a-f]{6}" let hcl = re"#[0-9a-f]{6}"
let ecl = re"(amb|blu|brn|gry|grn|hzl|oth)" let ecl = re"(amb|blu|brn|gry|grn|hzl|oth)"
let pid = re"\d{9}" let pid = re"^\d{9}$"
let validators = { let validators = {
"hgt": (v: string) => "hgt": (v: string) =>
@ -51,5 +51,4 @@ proc part1*(s: Stream): int =
toSeq(s.asPassports).filterIt(it.hasRequiredFields).len toSeq(s.asPassports).filterIt(it.hasRequiredFields).len
proc part2*(s: Stream): int = proc part2*(s: Stream): int =
# TODO: off-by-one error? toSeq(s.asPassports).filterIt(it.hasRequiredFields and it.isValid).len
toSeq(s.asPassports).filterIt(it.hasRequiredFields and it.isValid).len - 1