From 5277507ede3744d0d68292d512986dbdbdf2a4c7 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Fri, 4 Dec 2020 09:35:04 -0600 Subject: [PATCH] Fix "off-by-one" --- 2020/src/day4.nim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/2020/src/day4.nim b/2020/src/day4.nim index 30ab398..1c0b39b 100644 --- a/2020/src/day4.nim +++ b/2020/src/day4.nim @@ -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