Browse Source

Performance improvement for day 6

master
Chris Smith 5 years ago
parent
commit
8890f63c40
1 changed files with 5 additions and 1 deletions
  1. 5
    1
      day06.nim

+ 5
- 1
day06.nim View File

@@ -28,7 +28,11 @@ func nearest(coords: seq[Point], point: Point): int =
28 28
         -1
29 29
 
30 30
 func inrange(coords: seq[Point], point: Point): bool =
31
-    coords.map(proc (coord: Point): int = coord.distance(point)).sum < 10000
31
+    var sum: int
32
+    for coord in coords:
33
+        sum += coord.distance(point)
34
+        if sum >= 10000: return false
35
+    return true
32 36
 
33 37
 func part1(coords: seq[Point], extents: array[4, int]): int =
34 38
     var counts = newSeqWith(coords.len, 0)