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
         if count > 0:
8
         if count > 0:
9
             if (ord(c) xor ord(result[count - 1])) == 32:
9
             if (ord(c) xor ord(result[count - 1])) == 32:
10
                 result.delete(count - 1)
10
                 result.delete(count - 1)
11
-                count -= 1
11
+                count.dec
12
                 continue
12
                 continue
13
         result.add(c)
13
         result.add(c)
14
-        count += 1
14
+        count.inc
15
 
15
 
16
 let polymer = toSeq(readFile("data/05.txt").strip.items).react(' ')
16
 let polymer = toSeq(readFile("data/05.txt").strip.items).react(' ')
17
 
17
 

+ 5
- 2
day06.nim View File

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