瀏覽代碼

Remove python, use alpine. Holy speed, batman.

master
Chris Smith 5 年之前
父節點
當前提交
3d1cfc5734
共有 10 個檔案被更改,包括 5 行新增125 行删除
  1. 0
    17
      01.py
  2. 0
    27
      02.py
  3. 0
    30
      03.py
  4. 0
    21
      04.py
  5. 0
    20
      05.py
  6. 1
    2
      README.md
  7. 1
    1
      day08.nim
  8. 1
    3
      docker/Dockerfile
  9. 1
    3
      docker/entrypoint.sh
  10. 1
    1
      run.sh

+ 0
- 17
01.py 查看文件

@@ -1,17 +0,0 @@
1
-import itertools
2
-
3
-
4
-def first_duplicate(values):
5
-    seen = set()
6
-    for item in values:
7
-        if item in seen:
8
-            return item
9
-        seen.add(item)
10
-    return None
11
-
12
-
13
-with open('data/01.txt', 'r') as file:
14
-    frequencies = list(map(int, file.readlines()))
15
-
16
-    print(sum(frequencies))
17
-    print(first_duplicate(itertools.accumulate(itertools.cycle(frequencies))))

+ 0
- 27
02.py 查看文件

@@ -1,27 +0,0 @@
1
-import itertools
2
-import operator
3
-
4
-
5
-def count_dupes(box):
6
-    return [any(box.count(x) == i for x in box) for i in (2, 3)]
7
-
8
-
9
-with open('data/02.txt', 'r') as file:
10
-    boxes = list(map(str.strip, file.readlines()))
11
-
12
-    print(operator.mul(*map(sum, zip(*map(count_dupes, boxes)))))
13
-
14
-    for box1, box2 in itertools.combinations(boxes, 2):
15
-        common = ''
16
-        missed = 0
17
-        for i, j in zip(box1, box2):
18
-            if i == j:
19
-                common += i
20
-            else:
21
-                missed += 1
22
-                if missed > 1:
23
-                    break
24
-
25
-        if missed == 1:
26
-            print(common)
27
-            break

+ 0
- 30
03.py 查看文件

@@ -1,30 +0,0 @@
1
-import re
2
-from collections import defaultdict
3
-
4
-with open('data/03.txt', 'r') as file:
5
-    cells = defaultdict(lambda: 0)
6
-    claims = map(lambda l: map(int, re.findall(r'\d+', l)), file.readlines())
7
-    ids = set()
8
-    overlaps = 0
9
-
10
-    for (cid, x, y, width, height) in claims:
11
-        collision = False
12
-        for i in range(width):
13
-            for j in range(height):
14
-                previous = cells[(x + i, y + j)]
15
-                if previous == 0:
16
-                    cells[(x + i, y + j)] = cid
17
-                elif previous == -1:
18
-                    collision = True
19
-                else:
20
-                    collision = True
21
-                    overlaps += 1
22
-                    if previous in ids:
23
-                        ids.remove(previous)
24
-                    cells[(x + i, y + j)] = -1
25
-
26
-        if not collision:
27
-            ids.add(cid)
28
-
29
-    print(overlaps)
30
-    print(list(ids)[0])

+ 0
- 21
04.py 查看文件

@@ -1,21 +0,0 @@
1
-from collections import defaultdict, Counter
2
-
3
-sleeps = defaultdict(Counter)
4
-
5
-with open('data/04.txt', 'r') as file:
6
-    guard = sleep = 0
7
-
8
-    for log in sorted(line.strip() for line in file):
9
-        action = log[-5:]
10
-        if action == 'shift':
11
-            guard = log[26:-13]
12
-        elif action == 'sleep':
13
-            sleep = int(log[15:17])
14
-        else:
15
-            sleeps[guard].update(range(sleep, int(log[15:17])))
16
-
17
-most_sleep = max(sleeps.items(), key=lambda p: sum(p[1].values()))
18
-print(int(most_sleep[0]) * most_sleep[1].most_common(1)[0][0])
19
-
20
-sleepiest_minute = max([(guard, times.most_common(1)[0]) for (guard, times) in sleeps.items()], key=lambda p: p[1][1])
21
-print(int(sleepiest_minute[0]) * sleepiest_minute[1][0])

+ 0
- 20
05.py 查看文件

@@ -1,20 +0,0 @@
1
-from functools import partial, reduce
2
-
3
-with open('data/05.txt', 'r') as file:
4
-    polymer = map(ord, file.readline().strip())
5
-
6
-
7
-def react(ignored, head, n):
8
-    if n == ignored or n ^ ignored == 32:
9
-        return head
10
-    elif not head:
11
-        return [n]
12
-    elif head[-1] ^ n == 32:
13
-        return head[0:-1]
14
-    else:
15
-        return head + [n]
16
-
17
-
18
-reacted = reduce(partial(react, 0), polymer, [])
19
-print(len(reacted))
20
-print(min(len(reduce(partial(react, i), reacted, [])) for i in range(ord('A'), ord('Z'))))

+ 1
- 2
README.md 查看文件

@@ -1,7 +1,6 @@
1 1
 # Advent of Code 2018
2 2
 
3
-This repository contains my solution to 2018's [Advent of Code](https://adventofcode.com/2018) puzzles. The solutions
4
-are a mixture of Python 3 and Nim.
3
+This repository contains my solution to 2018's [Advent of Code](https://adventofcode.com/2018) puzzles in Nim.
5 4
 
6 5
 The easiest way to run these is using docker -- simply execute `run.sh <day>` to build a docker image and execute the
7 6
 specific day.

+ 1
- 1
day08.nim 查看文件

@@ -16,7 +16,7 @@ func readNode(input: var seq[string]): tuple[value: int, metasum: int] =
16 16
 
17 17
     for m in 0..meta_count-1:
18 18
         var v = input.pop.parseInt
19
-        if v > 0 and v - 1 < child_count:
19
+        if v > 0 and v <= child_count:
20 20
             value += child_values[v - 1]
21 21
         metasum += v
22 22
     

+ 1
- 3
docker/Dockerfile 查看文件

@@ -1,6 +1,4 @@
1
-FROM nimlang/nim
2
-
3
-RUN apt-get update && apt-get install -y pypy
1
+FROM nimlang/nim:alpine
4 2
 
5 3
 ADD entrypoint.sh /entrypoint.sh
6 4
 RUN chmod +x /entrypoint.sh

+ 1
- 3
docker/entrypoint.sh 查看文件

@@ -1,10 +1,8 @@
1
-#!/bin/bash
1
+#!/bin/sh
2 2
 
3 3
 cd /code
4 4
 
5 5
 if [ -f "day$1.nim" ]; then
6 6
     HOME=/tmp nim c --opt:speed -d:release day$1.nim >/dev/null 2>&1
7 7
     time ./day$1
8
-else
9
-    time pypy "$1.py"
10 8
 fi

+ 1
- 1
run.sh 查看文件

@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-IMAGE=csmith/aoc-2018-03
3
+IMAGE=csmith/aoc-2018-04
4 4
 
5 5
 docker image inspect $IMAGE >/dev/null 2>&1
6 6
 if [ $? -ne 0 ]