From 3e89255cdb49ea9944572b22ca49d5555a05ea91 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 9 Dec 2020 09:44:13 -0600 Subject: [PATCH] Cleanup and ready for day 10 --- 2020/src/aoc2020.nim | 3 +-- 2020/src/day1.nim | 1 - 2020/src/day10.nim | 7 +++++++ 2020/src/day9.nim | 4 +--- 4 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 2020/src/day10.nim diff --git a/2020/src/aoc2020.nim b/2020/src/aoc2020.nim index 2f29270..02f0614 100644 --- a/2020/src/aoc2020.nim +++ b/2020/src/aoc2020.nim @@ -9,5 +9,4 @@ proc solve_for_day(n: int) {.used.} = when isMainModule: # solve_all() - # solve_for_day(1) - solve_for_day(9) + solve_for_day(10) diff --git a/2020/src/day1.nim b/2020/src/day1.nim index 1fa970f..96e87e6 100644 --- a/2020/src/day1.nim +++ b/2020/src/day1.nim @@ -4,7 +4,6 @@ let targetSum = 2020 proc findComplement*(nums: openArray[int], complement = targetSum): Option[(int, int)] = var targets = initHashSet[int]() - echo nums for n in nums: if targets.contains(complement - n): return some(((complement - n), n)) else: targets.incl n diff --git a/2020/src/day10.nim b/2020/src/day10.nim new file mode 100644 index 0000000..7a4ee8f --- /dev/null +++ b/2020/src/day10.nim @@ -0,0 +1,7 @@ +import streams + +proc part1*(s: Stream): int = + 0 + +proc part2*(s: Stream): int = + 0 diff --git a/2020/src/day9.nim b/2020/src/day9.nim index a8f71cd..d910651 100644 --- a/2020/src/day9.nim +++ b/2020/src/day9.nim @@ -5,11 +5,11 @@ const WINDOW = 25 proc part1*(s: Stream): int = var rollingWindow = initDeque[int](WINDOW) for i in s.asInts: - echo i if rollingWindow.len < WINDOW: rollingWindow.addFirst(i) continue else: + # TODO: this toSeq every iteration is probably nasty let maybe = toSeq(rollingWindow).findComplement(i) if maybe.isSome: rollingWindow.addFirst(i) @@ -24,11 +24,9 @@ proc part2*(s: Stream): int = var mn = n var mx = 0 var sum = nums[i] - echo i, " i: ", nums[i] mn = min(nums[i], mn) mx = max(nums[i], mx) for j in i+1..