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
1 changed files with 2 additions and 3 deletions

View File

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