diff --git a/2020/src/day2.nim b/2020/src/day2.nim index 5e89862..f0d82f9 100644 --- a/2020/src/day2.nim +++ b/2020/src/day2.nim @@ -20,13 +20,11 @@ iterator asPasswordPolicies(s: Stream): (PasswordPolicy, string) = yield parsePasswordPolicy line proc part1*(s: Stream): int = - result = 0 for (pp, pw) in asPasswordPolicies(s): if isValidPassword(pw, pp): result += 1 proc part2*(s: Stream): int = - result = 0 for (pp, pw) in asPasswordPolicies(s): if isValidPasswordPart2(pw, pp): result += 1 diff --git a/2020/src/day3.nim b/2020/src/day3.nim index 353a010..08c9fa7 100644 --- a/2020/src/day3.nim +++ b/2020/src/day3.nim @@ -1,10 +1,7 @@ import streams proc sled(s: Stream, velx: int, vely: int): int = - setPosition(s, 0) - result = 0 - var xpos = 0 - var ypos = 0 + var xpos, ypos: int for line in s.lines(): ypos += 1 if (ypos - 1) mod vely > 0: @@ -19,5 +16,6 @@ proc part1*(s: Stream): int = proc part2*(s: Stream): int = result = part1(s) for vels in [(1, 1), (5, 1), (7, 1), (1, 2)]: + setPosition(s, 0) let (velx, vely) = vels result *= sled(s, velx, vely)