Skip to content

Commit 8df4a24

Browse files
committed
added 2018/day06
1 parent 1d07c12 commit 8df4a24

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

2018/day06/input.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
108, 324
2+
46, 91
3+
356, 216
4+
209, 169
5+
170, 331
6+
332, 215
7+
217, 104
8+
75, 153
9+
110, 207
10+
185, 102
11+
61, 273
12+
233, 301
13+
278, 151
14+
333, 349
15+
236, 249
16+
93, 155
17+
186, 321
18+
203, 138
19+
103, 292
20+
47, 178
21+
178, 212
22+
253, 174
23+
348, 272
24+
83, 65
25+
264, 227
26+
239, 52
27+
243, 61
28+
290, 325
29+
135, 96
30+
165, 339
31+
236, 132
32+
84, 185
33+
94, 248
34+
164, 82
35+
325, 202
36+
345, 323
37+
45, 42
38+
292, 214
39+
349, 148
40+
80, 180
41+
314, 335
42+
210, 264
43+
302, 108
44+
235, 273
45+
253, 170
46+
150, 303
47+
249, 279
48+
255, 159
49+
273, 356
50+
275, 244

2018/day06/run.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#! /usr/bin/env python3
2+
3+
def load_data(filename):
4+
with open(filename, 'r') as f:
5+
for line in f:
6+
line = line.rstrip('\n')
7+
t = line.split(', ')
8+
yield int(t[0]), int(t[1])
9+
10+
import numpy as np
11+
12+
coords = np.array(list(load_data('input.txt')))
13+
14+
# Part One
15+
16+
def distances(coords, pad):
17+
coords = np.transpose(coords)[:, :, np.newaxis, np.newaxis]
18+
min_x, max_x = np.min(coords[0]) - pad, np.max(coords[0]) + pad
19+
min_y, max_y = np.min(coords[1]) - pad, np.max(coords[1]) + pad
20+
grid = np.mgrid[min_y:max_y+1, min_x:max_x+1][:, np.newaxis, :, :]
21+
return np.abs(grid[0] - coords[1]) + np.abs(grid[1] - coords[0])
22+
23+
def area(coords, pad):
24+
d = distances(coords, pad)
25+
mask = d == np.min(d, axis=0)
26+
mask[:, *np.where(np.sum(mask, axis=0) > 1)] = False
27+
return np.sum(mask, axis=(1, 2))
28+
29+
a1 = area(coords, 0)
30+
a2 = area(coords, 1)
31+
32+
a1[np.where(a1 != a2)] = 0
33+
print(np.max(a1))
34+
35+
# Part Two
36+
37+
def area2(coords, pad):
38+
d = distances(coords, pad)
39+
s = np.sum(d, axis=0)
40+
return np.sum(s < 10000)
41+
42+
print(area2(coords, 0))

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
2015 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
33
2016 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
44
2017 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
5-
2018 ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
5+
2018 ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
66
2019 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- ++ ++ -- +- ++ +- -
77
2020 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +- ++ ++ ++ ++ ++ +
88
2021 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +

0 commit comments

Comments
 (0)