Browse Source

func!

master
Chris Smith 5 years ago
parent
commit
47bf49da5f
3 changed files with 6 additions and 6 deletions
  1. 2
    2
      day01.nim
  2. 3
    3
      day02.nim
  3. 1
    1
      day05.nim

+ 2
- 2
day01.nim View File

2
 
2
 
3
 let input = readFile("data/01.txt").strip.splitLines.map(parseInt)
3
 let input = readFile("data/01.txt").strip.splitLines.map(parseInt)
4
 
4
 
5
-proc part1(freqs: seq[int]): int =
5
+func part1(freqs: seq[int]): int =
6
     freqs.sum
6
     freqs.sum
7
 
7
 
8
-proc part2(freqs: seq[int]): int =
8
+func part2(freqs: seq[int]): int =
9
     var
9
     var
10
         seen = initIntSet()
10
         seen = initIntSet()
11
         talley: int
11
         talley: int

+ 3
- 3
day02.nim View File

1
 import sequtils, strutils
1
 import sequtils, strutils
2
 
2
 
3
-proc checksum(ids: seq[string]): int =
3
+func checksum(ids: seq[string]): int =
4
     var pairCount, tripCount: int
4
     var pairCount, tripCount: int
5
     for id in ids:
5
     for id in ids:
6
         var pairs, trips: bool
6
         var pairs, trips: bool
16
                 break
16
                 break
17
     pairCount * tripCount
17
     pairCount * tripCount
18
 
18
 
19
-proc difference(pairs: seq[tuple[a: char, b: char]]): string =
19
+func difference(pairs: seq[tuple[a: char, b: char]]): string =
20
     var difference: bool
20
     var difference: bool
21
     for pair in pairs:
21
     for pair in pairs:
22
         if pair.a != pair.b:
22
         if pair.a != pair.b:
27
         else:
27
         else:
28
             result &= pair.a
28
             result &= pair.a
29
 
29
 
30
-proc max_common(ids: seq[string]): string =
30
+func max_common(ids: seq[string]): string =
31
     for i, id1 in ids:
31
     for i, id1 in ids:
32
         for id2 in ids[i+1 .. ids.high]:
32
         for id2 in ids[i+1 .. ids.high]:
33
             let difference = zip(id1, id2).difference
33
             let difference = zip(id1, id2).difference

+ 1
- 1
day05.nim View File

1
 import sequtils, strutils
1
 import sequtils, strutils
2
 
2
 
3
-proc react(polymer: seq[char], skip: char): seq[char] =
3
+func react(polymer: seq[char], skip: char): seq[char] =
4
     var count = 0
4
     var count = 0
5
     for c in polymer:
5
     for c in polymer:
6
         if c == skip or (ord(c) xor ord(skip)) == 32:
6
         if c == skip or (ord(c) xor ord(skip)) == 32: