Browse Source

Style tweaks

master
Chris Smith 5 years ago
parent
commit
3f80651927
2 changed files with 7 additions and 4 deletions
  1. 2
    2
      day05.nim
  2. 5
    2
      day06.nim

+ 2
- 2
day05.nim View File

@@ -8,10 +8,10 @@ func react(polymer: seq[char], skip: char): seq[char] =
8 8
         if count > 0:
9 9
             if (ord(c) xor ord(result[count - 1])) == 32:
10 10
                 result.delete(count - 1)
11
-                count -= 1
11
+                count.dec
12 12
                 continue
13 13
         result.add(c)
14
-        count += 1
14
+        count.inc
15 15
 
16 16
 let polymer = toSeq(readFile("data/05.txt").strip.items).react(' ')
17 17
 

+ 5
- 2
day06.nim View File

@@ -22,7 +22,10 @@ func nearest(coords: seq[Point], point: Point): int =
22 22
         distances = coords.map(proc(coord: Point): int = coord.distance(point))
23 23
         lowest = min(distances)
24 24
         lowest_count = distances.filter(proc (distance: int): bool = distance == lowest).len
25
-    if lowest_count == 1: distances.find(lowest) else: -1
25
+    if lowest_count == 1:
26
+        distances.find(lowest)
27
+    else:
28
+        -1
26 29
 
27 30
 func inrange(coords: seq[Point], point: Point): bool = coords.map(proc (coord: Point): int =
28 31
     coord.distance(point)).sum < 10000
@@ -36,7 +39,7 @@ func part1(coords: seq[Point], extents: array[4, int]): int =
36 39
         for y in extents[2] .. extents[3]:
37 40
             let coord = coords.nearest([x, y])
38 41
             if coord != -1:
39
-                counts[coord] += 1
42
+                counts[coord].inc
40 43
                 
41 44
                 # If the area reaches the edge of the grid, it will continue infinitely.
42 45
                 # Mark that area as excluded.