summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom van der Lee <t0m.vd.l33@gmail.com>2022-12-19 09:30:43 +0100
committerGravatar Tom van der Lee <t0m.vd.l33@gmail.com>2022-12-19 09:30:43 +0100
commitf3d0899dbfd0aa3e6aebf5d19ec89d58ead418b2 (patch)
tree535a7048c7547e1eaef6f97dcfd8b2cad598ca50
parent06cb539f69f0b501afaa9ef5b6d89863e1c9d111 (diff)
download2022-f3d0899dbfd0aa3e6aebf5d19ec89d58ead418b2.tar.gz
2022-f3d0899dbfd0aa3e6aebf5d19ec89d58ead418b2.tar.bz2
2022-f3d0899dbfd0aa3e6aebf5d19ec89d58ead418b2.zip
Day 18
-rw-r--r--aoc/datastructures.py68
-rw-r--r--aoc/mixins.py20
-rw-r--r--aoc/tests/__init__.py0
-rw-r--r--aoc/tests/test_datastructures.py16
-rw-r--r--day17/__init__.py12
-rw-r--r--day18/__init__.py75
-rw-r--r--day18/example.txt13
-rw-r--r--day18/input.txt2057
-rw-r--r--day18/test_init.py24
9 files changed, 2279 insertions, 6 deletions
diff --git a/aoc/datastructures.py b/aoc/datastructures.py
index 81a68e4..244aa1e 100644
--- a/aoc/datastructures.py
+++ b/aoc/datastructures.py
@@ -1,5 +1,6 @@
1# -*- coding: utf-8 -*- 1# -*- coding: utf-8 -*-
2from collections import namedtuple 2from collections import namedtuple
3from typing import Iterator
3 4
4 5
5class Coordinate(namedtuple("Coordinate", ["x", "y"])): 6class Coordinate(namedtuple("Coordinate", ["x", "y"])):
@@ -28,3 +29,70 @@ class Coordinate(namedtuple("Coordinate", ["x", "y"])):
28 px, 29 px,
29 py, 30 py,
30 ) 31 )
32
33 def neighbours(self, no_diagonal: bool = False) -> Iterator["Coordinate"]:
34 if no_diagonal:
35 yield self + Coordinate(-1, 0),
36 yield self + Coordinate(1, 0),
37 yield self + Coordinate(0, -1),
38 yield self + Coordinate(0, 1),
39 else:
40 for dy in range(self.y - 1, self.y + 2):
41 for dx in range(self.x - 1, self.x + 2):
42 if dy == self.y and dx == self.x:
43 continue
44
45 yield Coordinate(dx, dy)
46
47
48class Coordinate3(namedtuple("Coordinate3", ["x", "y", "z"])):
49 def __sub__(self, other: "Coordinate3") -> "Coordinate3":
50 return Coordinate3(self.x - other.x, self.y - other.y, self.z - other.z)
51
52 def __add__(self, other: "Coordinate3") -> "Coordinate3":
53 return Coordinate3(self.x + other.x, self.y + other.y, self.z + other.z)
54
55 def manhattan_distance(self, other: "Coordinate3") -> int:
56 return abs(self.x - other.x) + abs(self.y - other.y) + abs(self.z - other.z)
57
58 @property
59 def polarity(self) -> "Coordinate3":
60 try:
61 px = abs(self.x) / self.x
62 except ZeroDivisionError:
63 px = 0
64
65 try:
66 py = abs(self.y) / self.y
67 except ZeroDivisionError:
68 py = 0
69
70 try:
71 pz = abs(self.z) / self.z
72 except ZeroDivisionError:
73 pz = 0
74
75 return Coordinate3(
76 px,
77 py,
78 pz,
79 )
80
81 def neighbours(self, no_diagonal: bool = False) -> Iterator["Coordinate3"]:
82 if no_diagonal:
83 yield self + Coordinate3(-1, 0, 0)
84 yield self + Coordinate3(1, 0, 0)
85 yield self + Coordinate3(0, -1, 0)
86 yield self + Coordinate3(0, 1, 0)
87 yield self + Coordinate3(0, 0, -1)
88 yield self + Coordinate3(0, 0, 1)
89 else:
90 for dz in range(self.z - 1, self.z + 2):
91 for dy in range(self.y - 1, self.y + 2):
92 for dx in range(self.x - 1, self.x + 2):
93 coordinate = Coordinate3(dx, dy, dz)
94
95 if dy == self.y and dx == self.x:
96 continue
97
98 yield coordinate
diff --git a/aoc/mixins.py b/aoc/mixins.py
index faeb3eb..5986b6e 100644
--- a/aoc/mixins.py
+++ b/aoc/mixins.py
@@ -55,3 +55,23 @@ class AStarMixin(Generic[Node]):
55 55
56 if neighbour not in open_nodes: 56 if neighbour not in open_nodes:
57 open_nodes.add(neighbour) 57 open_nodes.add(neighbour)
58
59
60class BreathFirstSearchMixin(Generic[Node]):
61 @staticmethod
62 def bfs(
63 start: Node, neighbours: Callable[[Node], Iterator[Node]]
64 ) -> Iterator[Node]:
65 queue = [start]
66 searched = set()
67
68 while len(queue):
69 item = queue.pop(0)
70
71 for neighbour in neighbours(item):
72 if neighbour not in searched and neighbour not in set(queue):
73 queue.append(neighbour)
74
75 searched.add(item)
76
77 yield item
diff --git a/aoc/tests/__init__.py b/aoc/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/aoc/tests/__init__.py
diff --git a/aoc/tests/test_datastructures.py b/aoc/tests/test_datastructures.py
new file mode 100644
index 0000000..a7965f5
--- /dev/null
+++ b/aoc/tests/test_datastructures.py
@@ -0,0 +1,16 @@
1# -*- coding: utf-8 -*-
2from aoc.datastructures import Coordinate3
3
4
5class TestCoordinate3:
6 def test_neighbours_nodiagonal(self):
7 coordinate = Coordinate3(0, 0, 0)
8
9 assert set(coordinate.neighbours(True)) == {
10 Coordinate3(-1, 0, 0),
11 Coordinate3(1, 0, 0),
12 Coordinate3(0, -1, 0),
13 Coordinate3(0, 1, 0),
14 Coordinate3(0, 0, -1),
15 Coordinate3(0, 0, 1),
16 }
diff --git a/day17/__init__.py b/day17/__init__.py
index 41b25dc..03e9003 100644
--- a/day17/__init__.py
+++ b/day17/__init__.py
@@ -30,12 +30,12 @@ class AssignmentOne(Assignment):
30 30
31 moves = self.infinite_moves(input) 31 moves = self.infinite_moves(input)
32 32
33 for move in self.infinite_moves(next(input)): 33 # for move in self.infinite_moves(next(input)):
34 i += 1 34 # i += 1
35 print(move) 35 # print(move)
36 36 #
37 if i == 100: 37 # if i == 100:
38 break 38 # break
39 39
40 40
41class AssignmentTwo(Assignment): 41class AssignmentTwo(Assignment):
diff --git a/day18/__init__.py b/day18/__init__.py
new file mode 100644
index 0000000..0500963
--- /dev/null
+++ b/day18/__init__.py
@@ -0,0 +1,75 @@
1# -*- coding: utf-8 -*-
2from abc import ABC
3from typing import Iterator, Set
4
5from aoc import BaseAssignment
6from aoc.datastructures import Coordinate3
7from aoc.mixins import BreathFirstSearchMixin
8
9
10class Assignment(BaseAssignment[int, Coordinate3], ABC):
11 def parse_item(self, item: str) -> Coordinate3:
12 x, y, z = item.split(",")
13 return Coordinate3(int(x), int(y), int(z))
14
15 @staticmethod
16 def open_sides(blocks: Set[Coordinate3]) -> int:
17 return len(
18 [
19 neighbour
20 for block in blocks
21 for neighbour in block.neighbours(True)
22 if neighbour not in blocks
23 ]
24 )
25
26
27class AssignmentOne(Assignment):
28 example_result = 64
29
30 def run(self, input: Iterator[Coordinate3]) -> int:
31 blocks = set(input)
32 return self.open_sides(blocks)
33
34
35class AssignmentTwo(Assignment, BreathFirstSearchMixin[Coordinate3]):
36 example_result = 58
37
38 def run(self, input: Iterator[Coordinate3]) -> int:
39 blocks = set(input)
40
41 lower_x = min([block.x for block in blocks]) - 1
42 higher_x = max([block.x for block in blocks]) + 1
43 lower_y = min([block.y for block in blocks]) - 1
44 higher_y = max([block.y for block in blocks]) + 1
45 lower_z = min([block.z for block in blocks]) - 1
46 higher_z = max([block.z for block in blocks]) + 1
47
48 all_coordinates = set(
49 Coordinate3(x, y, z)
50 for x in range(lower_x, higher_x + 1)
51 for y in range(lower_y, higher_y + 1)
52 for z in range(lower_z, higher_z + 1)
53 )
54
55 def nb(c):
56 for n in c.neighbours(True):
57 if n in all_coordinates and n not in blocks:
58 yield n
59
60 outer_coordinates = {
61 coordinate
62 for coordinate in self.bfs(
63 Coordinate3(lower_x, lower_y, lower_z),
64 neighbours=nb,
65 )
66 }
67
68 return len(
69 [
70 neighbour
71 for block in blocks
72 for neighbour in block.neighbours(True)
73 if neighbour in outer_coordinates
74 ]
75 )
diff --git a/day18/example.txt b/day18/example.txt
new file mode 100644
index 0000000..73a7202
--- /dev/null
+++ b/day18/example.txt
@@ -0,0 +1,13 @@
12,2,2
21,2,2
33,2,2
42,1,2
52,3,2
62,2,1
72,2,3
82,2,4
92,2,6
101,2,5
113,2,5
122,1,5
132,3,5
diff --git a/day18/input.txt b/day18/input.txt
new file mode 100644
index 0000000..acf8240
--- /dev/null
+++ b/day18/input.txt
@@ -0,0 +1,2057 @@
14,15,12
216,10,16
315,15,10
414,11,16
55,7,15
615,9,12
78,5,3
82,9,10
913,16,9
102,7,9
116,5,5
1217,7,10
136,13,15
143,14,13
154,14,13
163,6,7
175,16,7
186,16,12
1916,13,6
204,10,4
213,5,8
223,14,9
2314,9,1
2416,5,9
2516,12,15
2616,7,6
274,4,9
2817,13,10
2913,4,14
309,2,10
315,4,12
326,9,16
3310,2,13
3418,10,8
356,4,4
365,14,5
377,9,18
387,14,16
397,4,15
409,11,17
4112,10,16
422,6,8
435,13,4
4412,2,9
4514,4,16
469,8,4
474,10,3
485,14,4
4913,16,13
5011,8,17
5116,8,15
523,12,12
5313,13,16
5415,7,6
5513,16,7
562,10,9
573,11,5
583,9,4
5911,15,14
6013,6,13
614,12,4
626,2,9
635,13,9
643,7,7
6514,8,16
665,16,11
677,16,13
687,6,3
698,4,4
7014,16,8
7118,7,9
727,4,14
7314,11,4
747,9,3
7512,8,1
7611,8,1
776,15,7
7811,2,12
791,7,9
8011,10,17
812,11,6
8213,10,3
8316,13,12
845,8,3
858,5,2
8611,7,2
877,18,12
8814,7,3
895,10,16
9016,7,12
919,7,1
929,16,7
936,9,17
9416,11,8
9514,12,4
9611,12,3
977,17,12
9811,3,4
995,5,14
1003,13,8
1017,17,8
1024,10,12
10316,15,8
10416,11,15
1053,3,9
10615,6,9
10712,4,7
10816,10,14
10916,9,5
1107,12,17
11117,13,9
1122,10,8
1135,3,10
11417,8,5
11512,17,13
1169,15,12
1178,6,16
1188,14,3
1197,2,12
12017,9,6
1217,11,17
12212,5,3
12315,16,9
1248,10,0
12514,9,17
1263,11,9
12715,7,15
1288,16,14
1293,12,15
13015,14,13
1312,9,12
13214,3,7
1339,4,5
13412,2,6
13512,16,11
13613,2,9
1377,15,14
1387,5,3
13917,7,7
1406,8,17
14110,1,9
14210,4,5
1434,17,10
14410,18,10
1458,7,16
1465,2,7
1477,11,2
1482,11,11
14910,3,15
1509,15,14
1519,4,4
1529,11,1
1538,12,16
1547,8,1
15510,3,5
15614,16,10
1574,7,16
1587,12,3
15916,13,14
1604,14,10
16113,2,7
1628,18,7
16310,15,3
1646,5,14
16518,11,12
1664,15,13
16715,5,14
16814,15,14
16910,17,13
1704,15,7
1713,7,12
1727,5,15
17314,4,8
1742,12,11
1759,3,12
17614,9,18
17713,8,2
1785,13,6
17911,16,14
18016,14,8
18116,14,7
18215,10,4
18319,11,9
18412,3,6
18518,11,6
18613,2,12
18714,16,12
18815,10,5
18917,13,6
1903,11,6
19111,3,8
1927,6,17
1933,8,14
19417,6,10
1955,4,8
1969,3,15
19711,13,14
1986,14,6
1995,9,2
20011,5,9
2013,14,10
2024,10,16
2038,6,1
2049,15,4
2059,16,9
20610,4,4
2077,2,10
20813,3,12
2096,6,4
2102,8,12
21118,12,8
2129,9,16
21312,17,15
2144,16,10
2159,16,6
21615,14,5
2174,12,5
21815,4,9
21911,11,2
2209,18,10
22115,5,13
2221,9,8
22316,6,8
22412,2,8
2259,16,12
2267,11,16
2273,10,16
22811,9,16
2293,4,10
23016,12,11
23117,8,13
2324,6,7
2332,7,11
2343,8,16
2359,17,7
23612,9,17
2373,11,7
23814,15,10
23916,5,12
24010,3,7
24115,13,3
2421,10,11
24311,2,6
2447,16,6
2457,12,18
24613,10,17
2475,4,11
24812,13,17
2497,7,17
25012,16,7
2512,8,10
2523,12,8
25316,11,6
25414,5,5
25515,4,10
25614,16,9
2579,3,7
2584,5,12
25911,6,18
2605,3,7
2612,7,7
26215,11,5
2635,3,11
2647,17,11
2658,9,17
26615,5,7
2677,9,17
26814,13,14
26913,6,14
2709,11,2
2715,8,4
27213,5,4
27318,11,13
2747,7,4
27514,8,5
27615,6,6
27713,7,4
27813,3,7
2799,17,11
28016,9,7
28113,16,14
28215,11,16
2839,15,6
2847,17,9
2853,13,11
2864,12,14
2874,6,11
28816,14,13
28910,3,14
29014,7,6
29115,5,5
2924,12,11
2939,7,2
29417,11,12
29516,13,7
29611,8,2
2978,2,8
29815,13,4
29912,3,5
3004,11,5
3019,12,2
30210,15,15
3034,6,4
3049,6,16
3052,8,11
30617,7,12
3073,14,8
30814,4,14
30913,12,15
3103,11,12
3118,17,5
3125,3,13
31310,11,17
31416,10,13
31514,10,3
31613,4,7
31716,7,13
31818,8,11
3198,3,13
3203,8,12
32115,16,13
32217,14,9
3236,2,12
32417,15,10
32510,5,15
32613,16,10
32716,6,15
3286,15,15
3296,7,16
33014,17,9
33110,12,3
3324,7,14
33313,11,2
3348,11,2
33516,6,11
3368,5,5
3377,14,3
3388,17,6
3394,13,5
3407,3,9
3412,8,13
34212,16,6
34317,10,7
34414,7,2
3457,7,16
3467,4,7
3479,2,13
3488,8,17
3498,4,9
35016,12,7
35116,9,15
3528,14,4
35315,6,10
35416,7,14
3557,1,6
35612,7,2
3577,8,2
35810,14,4
3593,14,11
36012,6,15
36114,14,9
36216,5,8
36310,15,11
3642,10,11
3659,14,3
3664,8,5
3677,10,17
3685,14,14
36916,8,5
3709,13,18
37116,3,10
37214,14,5
37311,5,16
3746,4,13
37517,12,7
3767,18,8
3776,6,16
3786,4,14
37913,17,8
3803,8,5
38112,15,15
3828,3,14
38310,16,10
3849,1,11
3856,14,7
38612,3,9
38717,9,13
3888,9,18
3899,15,16
3906,16,10
39112,15,13
3929,6,2
3931,9,12
3946,16,8
3959,6,1
39612,3,14
39710,9,17
39813,13,4
39913,15,7
40011,14,16
40116,10,6
40216,11,13
4035,10,3
4041,11,8
40511,16,8
40610,13,16
4073,3,11
40811,16,7
40914,4,10
41015,11,3
4115,4,6
4129,17,10
4136,15,12
41415,10,16
41511,14,3
4164,7,12
41714,6,3
41818,10,11
41916,5,11
42012,15,11
4216,16,7
42213,4,5
42314,9,4
42411,3,9
42518,7,11
42614,14,6
42711,1,9
42814,4,5
4296,9,3
4304,4,14
4312,13,7
4326,3,9
4336,4,7
4348,1,6
43518,12,10
4369,13,3
43717,13,11
4385,6,5
4394,12,12
4403,7,14
44117,11,6
44210,12,2
4439,2,7
4448,17,13
4455,13,3
4469,10,17
44714,3,10
44815,8,4
44915,5,11
4504,9,15
45117,7,11
4524,5,11
4532,9,11
45410,7,4
4555,17,10
4562,14,9
45713,12,16
45817,13,13
4594,7,5
4604,13,14
46113,4,13
4626,14,4
4635,9,14
4649,4,6
46512,7,16
4669,14,2
4677,17,6
4687,2,8
46913,1,11
47013,9,18
4716,4,16
47210,3,13
47314,5,15
47414,8,3
47514,16,4
4764,4,11
47712,8,18
4785,5,13
4792,9,8
48016,8,8
48115,11,7
4824,9,16
4832,13,11
4845,15,9
4854,8,6
48615,12,6
4874,12,6
48815,10,8
4899,2,4
49013,7,17
4914,14,6
4923,5,12
49315,7,13
4942,11,5
49512,2,11
4963,10,14
49710,9,18
4986,8,16
49911,6,3
5002,7,13
50112,14,16
5028,2,14
5036,17,7
5048,3,6
5058,3,11
50616,9,13
50715,10,14
5089,2,9
5098,16,5
51014,11,14
5113,8,13
51211,12,2
5137,4,4
5147,1,9
5159,13,2
51615,6,5
51711,3,12
51813,6,16
5192,5,6
52017,8,9
5218,4,14
5222,11,7
5236,12,4
5242,6,7
52514,13,6
52610,16,14
5275,3,6
52815,12,7
52917,8,12
5308,4,16
53111,9,1
53214,16,6
53311,11,16
53411,7,17
53510,17,11
5363,7,9
5379,9,17
53810,14,3
5398,5,16
5409,11,16
5418,12,17
5426,10,17
54311,17,11
54411,13,4
5453,7,8
54616,10,8
5476,15,6
54810,17,12
5494,13,8
5503,12,6
5514,4,12
55210,6,2
55310,2,10
55417,4,9
55517,8,14
55614,10,16
55712,7,15
55811,2,15
55916,13,13
56010,16,9
56116,4,7
5626,2,7
5636,4,15
56415,13,13
5655,12,14
56615,14,14
56711,3,6
56814,3,14
56912,7,3
57013,3,5
57110,6,16
57218,8,10
57311,12,16
5747,18,10
57511,4,16
5761,12,8
57711,2,10
5789,6,3
5792,7,14
5804,14,9
5817,14,4
5822,8,7
58310,18,11
58414,12,16
5854,16,11
5869,5,4
5875,11,2
5884,13,11
5898,15,4
5902,5,10
5919,1,6
5926,6,5
5938,4,6
59415,12,14
59512,2,10
5966,14,16
5979,11,18
59816,8,9
59914,3,8
60015,13,14
60113,14,16
6027,12,4
6036,17,12
6041,11,10
6057,9,2
6064,15,14
60713,15,5
60813,10,2
60911,2,8
6107,8,3
6118,18,8
6127,13,16
6134,11,16
61410,19,11
61511,7,16
61617,13,7
61712,5,15
61817,13,12
6192,12,12
62016,11,4
6214,10,14
62213,10,0
6238,11,18
62413,13,14
62512,12,2
62612,15,5
6274,5,14
62810,18,12
6296,13,4
63011,9,18
63114,3,13
6328,10,1
63311,7,3
63415,8,3
6355,13,15
6366,17,8
63715,12,12
6382,8,8
6395,14,11
6405,13,14
64112,2,5
6429,12,17
6436,11,16
6442,12,9
64514,11,15
64615,15,12
6474,14,14
6486,5,3
64912,17,11
6503,16,9
6512,9,14
65216,9,12
65317,5,11
65414,8,15
6559,7,17
6564,5,10
6575,14,8
6587,2,11
65918,8,13
6607,3,12
66112,5,16
66217,10,11
6639,3,14
6642,11,4
66513,3,13
6666,3,7
66714,14,7
66812,14,5
6696,13,3
6706,15,16
67116,13,5
67211,18,10
67316,9,6
67415,3,8
67515,15,7
67616,11,5
6773,9,5
6788,11,17
6798,8,2
6804,12,15
6816,3,6
6828,2,9
68316,12,13
68415,9,14
6859,14,16
68610,16,4
68716,7,10
68815,2,11
6892,8,5
69015,13,5
6913,6,9
69218,9,11
6933,4,7
69414,7,14
69511,11,17
6965,9,4
6972,9,9
6985,7,5
6996,12,3
7005,16,6
7018,13,16
70210,11,3
70312,14,3
7045,12,5
7053,7,6
70617,10,4
70716,6,9
7087,10,3
7093,6,6
71010,2,6
71110,3,10
7128,1,9
71314,9,14
71411,3,5
7152,6,11
7167,13,3
7178,4,10
71816,8,14
71916,10,15
72016,14,12
72116,9,10
72218,9,7
72317,8,8
7243,11,13
7259,3,9
7265,3,9
7276,15,4
72810,13,17
7292,9,6
7303,7,11
7315,6,4
73210,1,10
7336,3,11
7346,14,3
73512,16,14
73610,8,4
7379,10,1
7389,2,11
7396,4,12
7405,4,7
74110,6,3
7427,6,2
74316,12,5
74410,17,10
74514,5,14
74610,15,5
7479,10,16
74815,14,7
74910,17,8
7508,1,8
75114,3,11
75217,10,10
75314,13,13
7547,3,14
75516,14,11
75611,9,2
7574,13,4
7589,16,10
7599,17,5
7602,7,12
76112,12,1
7627,18,11
7632,11,15
76412,14,15
7653,14,6
7663,12,10
76712,11,17
7685,17,8
7693,6,13
7704,9,7
7715,6,3
7727,8,17
77313,2,13
7749,9,3
77513,8,4
77613,17,7
77714,8,14
77812,10,17
7791,9,9
78015,6,12
7818,3,5
7824,9,5
78310,10,2
7849,5,17
7853,15,10
78610,17,6
78716,14,9
78813,6,3
7893,15,9
7909,11,3
79113,9,15
7927,14,5
79315,11,4
7946,15,5
7957,1,8
79615,13,12
7977,1,11
79812,16,12
7993,14,14
8004,6,6
80110,9,3
80215,4,13
80317,12,8
8042,12,8
80516,6,12
8068,15,5
8079,6,17
80813,8,16
80916,13,9
8106,14,5
8118,7,2
81211,10,2
8135,9,3
81412,4,14
81510,7,2
8163,3,7
81712,9,1
81812,3,12
8195,16,12
82016,6,6
82110,3,8
82212,6,4
82310,13,4
8246,7,17
8252,9,7
82617,12,13
82716,9,4
8289,16,3
8293,16,8
83014,14,14
8317,4,13
8326,4,5
83314,3,12
83413,15,11
83518,9,8
8363,7,5
8378,3,9
83814,6,15
8394,3,7
84016,14,10
8418,14,14
84211,18,9
8437,3,10
8448,8,18
8454,11,15
8462,8,9
84712,5,2
8483,10,15
84913,16,5
8505,6,16
8511,12,11
85216,6,10
8535,11,14
85416,14,14
85510,11,0
85615,8,6
8578,5,4
85812,2,12
85912,3,11
86017,6,12
8616,12,17
8627,6,16
86311,17,14
8648,12,2
8651,9,11
86615,7,4
86711,2,13
8686,3,12
8697,12,2
87016,9,11
8715,15,6
87216,5,7
87313,12,17
87417,9,11
8759,8,2
87611,16,16
8775,12,16
87815,7,12
8793,10,7
88017,5,10
88115,8,13
88216,12,10
88317,11,7
8843,12,5
8853,12,9
8869,17,12
88715,3,9
88812,4,5
8894,6,8
89013,14,14
8919,8,1
8927,3,11
89311,16,10
89411,16,6
8959,5,2
89614,16,11
8971,12,9
8989,9,2
89917,7,8
9009,13,16
9018,15,15
90214,14,13
9031,7,10
90412,8,17
9054,11,3
9069,1,9
90712,10,3
90816,5,10
90913,5,16
9109,1,12
91114,15,8
91215,14,12
91310,2,14
91411,17,10
91517,10,12
9165,14,3
9173,7,10
91812,13,3
91916,14,5
9209,5,16
92111,14,2
92211,13,1
92310,8,18
9248,10,2
9259,10,18
9263,14,5
9275,10,4
9288,7,15
92911,3,13
93012,14,4
9316,13,5
9328,1,11
93315,14,10
93413,4,11
93510,15,6
93615,9,16
93718,9,10
9386,17,9
93915,10,3
94010,10,1
9414,5,13
94217,6,8
94314,13,3
94410,5,17
9459,14,15
9469,8,0
9477,3,6
9483,4,11
9492,8,14
9505,8,17
95115,5,9
95215,8,5
9534,10,15
95414,3,6
9555,14,6
9567,13,15
9575,5,4
95810,17,7
95913,13,17
9606,11,2
9618,10,17
9629,8,17
96317,6,7
96410,10,15
9654,14,7
9667,2,9
96711,15,11
9688,1,7
96914,7,17
97015,3,10
97112,10,1
97210,8,3
97313,3,9
97413,4,4
97511,6,17
97615,6,4
97715,7,3
9785,12,3
97913,16,12
9809,7,3
98115,6,11
9824,5,6
9836,14,14
98412,8,14
9858,15,16
98613,4,9
9876,10,16
98816,15,9
98910,15,4
9903,6,11
9913,7,13
99210,5,3
9938,6,3
99418,11,9
9958,16,13
9962,12,7
9979,18,11
9988,15,6
99912,13,14
100017,5,9
10016,11,14
100217,13,8
100310,15,7
100415,5,6
10055,5,6
10069,9,18
100714,7,8
10087,4,6
100914,15,13
101011,6,16
10114,12,7
101211,11,1
101312,4,13
101412,14,17
10159,17,6
10169,15,15
10176,17,11
10189,11,4
101912,17,9
102013,11,18
102116,5,13
102215,6,13
10234,12,9
102411,6,2
10253,11,11
102612,3,10
10276,15,11
102815,9,15
10294,15,8
103014,12,5
10319,17,8
10321,12,10
10332,13,12
103410,3,4
10355,4,4
103613,11,15
103714,10,4
10389,16,11
10391,13,8
10405,15,8
104111,2,5
10424,5,9
104313,11,17
10448,16,3
104510,5,2
10462,10,7
104713,15,6
104814,5,4
104910,13,2
105013,15,14
105110,7,3
10526,11,3
10531,9,7
10546,11,18
10556,4,10
105616,12,9
105710,4,3
10585,6,6
105915,5,8
10604,12,16
10618,16,7
106211,9,4
10636,7,3
106414,10,17
10655,13,5
10665,15,12
106711,15,15
106816,10,5
106913,17,6
107016,7,9
10712,11,12
10729,14,1
107310,10,18
10744,3,8
10757,16,5
10768,2,13
10778,17,11
107813,5,13
10798,2,11
10804,4,13
108113,7,16
10823,12,4
108314,6,5
10849,3,11
10858,12,1
108617,9,8
108712,4,6
108810,17,9
108914,6,14
10908,17,12
109110,1,7
109211,15,13
10934,7,4
10947,7,15
10952,6,12
109617,10,5
109716,9,3
10983,10,5
10997,10,15
110010,10,17
110111,5,4
110212,11,3
110310,2,5
11046,6,3
110511,1,8
11061,6,7
11076,8,4
11082,7,6
110912,16,5
11104,16,7
11114,6,10
11122,9,4
111312,9,18
11145,17,12
11155,5,8
111618,10,9
111714,2,7
11181,9,10
11198,10,5
11205,2,6
11218,3,12
112214,14,15
11236,16,11
11247,14,11
11252,9,13
11263,8,6
112716,12,4
11286,8,15
112910,16,13
11303,9,14
11312,6,6
11328,16,15
113311,4,15
11341,6,11
11357,16,15
113611,2,14
113711,3,11
113817,12,11
11396,3,14
114012,3,7
11412,5,11
114216,6,5
114313,18,10
11444,8,13
114514,17,11
11465,16,10
11478,17,10
114811,13,15
114915,15,8
11507,3,8
11514,13,15
115213,17,10
11534,2,10
11543,7,4
115510,12,18
11568,18,11
11571,13,9
11583,13,13
115911,5,15
116011,13,3
116115,15,9
116217,9,7
116315,4,6
11647,12,16
116515,13,9
11668,2,12
116714,4,7
116815,3,7
116911,7,1
11705,7,4
117113,7,3
117212,16,8
117315,5,12
11741,13,10
117510,15,13
117612,6,17
11775,17,7
11785,7,16
117912,18,8
11804,9,13
118111,10,1
11821,9,6
11837,15,15
118413,14,3
118517,10,13
118616,15,5
11874,3,10
118810,11,18
11893,6,12
11903,15,8
119111,15,5
119210,1,8
119312,4,4
119415,4,11
11953,12,11
119617,7,6
119714,4,9
11985,12,4
119912,5,5
12009,1,8
12019,4,16
12028,9,16
120312,1,11
120414,4,11
12052,15,10
120617,12,6
120712,8,2
120810,4,15
120912,7,14
12104,8,3
12113,10,4
12128,6,4
121317,11,8
121415,14,9
12157,6,4
121617,9,12
12173,9,7
12187,12,13
121914,15,5
122013,4,6
122110,12,1
122211,3,15
12232,6,9
122416,4,13
12259,5,13
12264,6,14
122713,9,2
122815,9,4
122917,11,13
12304,4,6
12316,14,13
123213,13,3
12339,8,3
123411,5,2
123513,11,14
123616,8,11
123716,10,10
123813,14,5
123914,5,9
12409,3,6
12411,11,6
124214,15,12
12439,18,8
124413,7,15
12451,10,7
12469,4,13
12477,15,8
12488,16,8
124912,9,3
12505,15,7
12513,9,16
12528,18,12
12536,2,8
12544,16,6
125511,15,4
12566,13,16
12578,10,3
125813,14,2
125911,11,18
12607,16,12
126115,6,14
126211,3,10
126311,4,7
126414,4,6
126512,3,8
126614,11,3
126716,7,11
12687,11,4
12692,13,9
127014,3,9
12715,2,10
12723,12,7
127313,15,13
12749,6,15
127513,7,2
127614,9,15
12779,1,10
127817,6,11
12799,12,16
128011,3,7
12818,11,16
128213,10,16
128311,15,12
128410,16,15
12854,15,10
128612,12,3
128714,17,10
12887,13,2
128910,5,16
129013,15,15
12915,4,13
12921,10,10
129314,15,9
12949,16,14
129518,14,9
129616,13,11
12975,15,13
12985,13,13
129910,17,4
13008,6,15
13011,7,11
13023,10,12
13034,11,6
130411,8,16
13052,7,8
13062,10,13
13078,4,7
13085,11,3
130910,15,16
13108,2,5
13117,5,6
13122,7,10
13136,5,4
13141,6,10
13155,15,4
13162,9,5
13175,15,14
13183,5,9
131912,11,18
13205,16,13
132110,8,1
132210,15,12
132310,2,12
132414,16,7
132513,11,3
132610,2,11
132711,17,13
13285,11,15
13297,13,17
133010,2,9
13315,7,3
133210,16,6
13335,6,14
13344,4,7
133513,9,17
133614,13,15
13373,14,7
133814,13,8
133918,12,13
134012,17,12
134116,9,8
13424,15,6
13439,15,13
13447,11,1
13453,10,8
134610,11,15
13473,13,6
13484,9,3
134912,6,2
135016,8,4
135117,7,9
13526,9,2
135313,2,11
135411,15,16
135510,10,3
13565,11,16
135715,8,12
13585,14,10
13598,12,3
13601,10,8
13614,10,6
13625,2,5
13633,13,9
13648,6,17
136515,11,15
13665,9,16
13677,17,10
13689,17,9
13697,16,4
13708,15,14
137110,13,3
137212,5,4
137315,16,10
13743,5,7
13757,3,13
137613,2,10
13778,13,17
13783,5,10
13796,15,14
138011,12,17
138115,15,11
13822,7,4
138310,9,0
138413,16,8
138517,8,7
13866,10,2
138711,14,17
138812,18,10
13894,8,15
13907,2,7
13918,16,9
13926,7,15
13935,5,3
139417,14,11
139515,4,7
139614,13,4
139713,3,6
139813,3,11
13997,15,4
140016,7,7
14019,16,13
140212,5,12
14037,10,16
140414,7,15
14055,12,13
140610,12,17
140713,13,15
140811,8,3
140917,9,14
141013,17,11
14111,8,10
14125,6,13
14134,17,12
14143,9,12
14154,11,4
14169,2,12
14175,16,14
141814,5,10
14193,8,11
142014,7,4
14219,17,14
14227,4,3
142315,7,5
142413,4,12
14255,1,10
142617,10,8
14278,14,17
14285,17,9
14293,11,15
143012,3,4
14314,13,6
14326,7,1
14331,10,9
143416,4,9
143517,5,8
14368,14,16
14375,4,9
143810,14,17
143916,6,13
14403,13,7
144117,14,10
14429,7,16
144314,9,3
144414,5,13
144514,11,2
14466,14,15
14476,5,6
144811,14,5
14495,12,15
14505,10,2
145112,13,15
145215,4,8
145312,15,6
145416,11,12
145513,5,5
145618,12,9
145711,4,4
145816,11,7
14595,7,2
146014,4,12
146111,5,17
14626,10,15
146313,10,4
14647,4,12
146512,11,16
14665,14,15
146718,9,9
14684,13,2
146916,13,8
14704,3,11
147115,4,14
14728,13,18
147311,7,4
14747,15,16
14759,18,12
14765,4,14
147712,17,7
14786,11,5
14796,14,10
14803,14,12
14819,4,14
14828,11,1
148314,2,9
148412,1,10
14854,13,13
14866,2,13
14875,8,15
148813,7,14
148917,11,11
149010,3,11
149110,15,14
14924,14,12
14935,13,16
14945,10,14
14954,7,13
14966,2,11
14975,11,17
149812,9,16
14991,8,13
15002,13,6
150113,3,8
150214,15,4
150316,15,7
150417,8,10
15054,13,3
15062,12,10
150712,15,7
15089,3,5
15096,3,10
151015,12,15
151111,17,9
151216,8,13
151317,11,14
15149,1,7
15156,10,4
15169,2,6
15174,15,9
15185,15,11
15197,16,9
15206,2,10
15218,5,14
152214,8,4
15237,4,11
152415,16,11
152516,12,14
15269,13,4
15278,3,15
152817,11,5
152915,6,7
153011,3,14
153118,9,12
153214,10,14
15332,11,13
153415,10,6
153517,10,9
15369,7,4
153714,10,5
153816,10,12
153910,7,17
15403,5,6
154113,16,6
154212,11,4
15437,16,8
15446,5,10
154513,14,4
154611,14,14
15476,8,2
15486,5,15
154917,8,6
15508,13,2
155114,15,11
15522,14,7
155315,12,4
155415,10,15
155513,4,16
155612,16,4
15576,13,6
155817,11,15
155912,11,2
156011,2,7
156114,13,16
156214,4,15
156316,9,14
15646,5,7
156512,16,13
15668,4,15
15678,3,4
156812,15,4
15699,8,16
15706,11,17
15715,15,10
15723,6,4
157311,4,8
15747,14,14
15755,4,10
157610,18,9
157714,12,3
157818,9,6
157914,14,10
15801,8,11
15815,14,12
158212,3,13
15839,16,5
158412,10,2
15853,9,13
158614,4,13
158716,15,11
15886,6,15
158914,13,17
15902,11,10
159114,16,14
15925,2,11
15938,15,2
15943,13,5
159510,7,16
159614,5,12
159715,8,16
159811,16,15
15999,3,13
16004,7,11
16014,6,5
160216,5,14
16032,14,8
16048,8,1
160517,6,9
160613,4,15
16072,8,6
160814,12,12
160913,4,3
16104,13,12
161116,8,16
16126,4,6
161312,13,5
161414,12,11
16158,11,14
16167,1,10
161718,11,10
16181,10,12
161915,16,8
16208,13,3
162111,13,2
162210,5,5
16234,15,11
162412,15,14
162512,16,15
16269,15,7
162712,15,16
16288,0,8
162910,18,8
16301,8,7
163118,6,10
163210,3,12
163313,9,4
16347,17,13
16356,14,2
163611,0,9
163716,12,6
163813,17,12
16394,4,10
164017,10,14
164116,8,12
16427,4,16
16431,10,6
16445,10,17
16456,13,14
164613,15,16
16476,7,5
16486,12,15
164916,4,10
165010,6,14
165114,6,4
16527,5,4
165316,7,8
165411,9,17
16555,9,15
165610,9,2
165711,5,3
16583,3,10
165910,16,5
166011,6,4
16614,10,5
16622,10,14
16637,15,11
166412,15,12
16655,14,13
166615,8,14
16676,13,17
16688,15,13
16697,2,13
167018,8,7
16717,16,16
167215,6,8
167312,7,18
167410,5,14
167517,9,10
167613,8,15
167718,11,7
167815,13,6
167910,6,17
16804,11,12
168118,11,8
168213,2,14
168312,17,10
16841,9,13
16853,13,12
168616,11,14
16879,5,6
168818,10,12
168915,9,6
169012,16,10
16917,5,16
169215,16,7
16939,16,15
16946,12,16
169513,9,1
169614,14,4
16972,13,10
16986,17,10
16995,11,9
17004,4,8
170119,7,9
170214,8,6
170314,13,5
17041,8,8
170512,17,6
170613,15,8
170715,3,11
17086,16,13
17097,15,10
17108,5,18
17115,4,3
171214,16,15
171313,6,17
171414,9,2
171516,10,4
17167,16,7
17179,3,16
17186,16,9
171910,8,17
17203,5,13
172113,13,6
17228,9,2
172313,16,11
172413,17,9
172514,15,7
17263,13,4
17275,8,16
17284,8,14
17298,18,9
17309,12,1
17313,5,11
173215,14,6
17335,8,2
173418,13,13
17354,10,17
17368,6,2
173714,11,17
173815,11,14
17394,7,6
17404,16,12
174116,6,7
174212,16,9
174312,2,7
17447,3,4
174514,9,16
17467,6,5
17475,16,9
17483,10,9
174910,10,16
17508,9,3
175117,10,6
17526,2,6
17534,16,9
17547,9,14
17557,3,15
17566,11,1
17579,12,19
175818,5,8
17596,11,4
176014,15,6
17619,4,15
176213,15,9
17632,14,13
17646,11,15
176513,9,16
17663,9,8
176710,7,18
176818,11,11
17696,10,3
177013,12,2
177110,16,7
17724,3,13
177317,12,12
177413,9,3
177515,12,5
17762,10,10
177712,7,17
177813,8,3
177912,15,3
178013,1,10
17818,10,18
17828,4,13
178311,2,11
17843,11,14
178513,13,2
178613,10,15
17877,3,7
178813,1,8
17894,16,8
179013,18,7
179114,11,5
17922,12,13
179315,2,8
17945,17,11
17952,13,14
179613,2,8
179712,5,14
17989,13,15
179914,14,12
18003,6,8
180115,15,13
18027,16,14
18034,13,9
180411,15,3
180515,16,12
18063,13,10
18079,2,8
180813,7,5
180915,14,16
181012,18,11
181112,13,16
181210,13,15
18138,15,3
18143,9,6
181517,11,9
18167,14,13
181713,5,15
18183,4,9
181910,2,8
18204,3,9
182115,15,6
18224,6,12
182313,8,17
182416,12,8
182516,4,8
18265,3,14
18279,18,9
18283,10,6
18297,4,5
183013,14,7
18315,10,6
18329,12,3
183314,10,15
183411,1,7
183518,6,9
183615,15,14
183717,8,11
18388,14,15
183916,12,12
184015,3,12
18414,11,14
184212,17,8
18438,1,12
18443,9,15
18453,15,12
184613,14,13
184712,6,16
184814,15,16
184910,4,17
185014,6,13
18513,8,9
18522,11,9
185310,6,15
18548,2,10
185512,14,2
185611,1,11
185715,9,8
18584,9,4
185911,10,5
18606,9,14
186117,7,13
186218,13,9
18638,7,1
18640,10,7
18659,6,4
18665,3,8
18678,5,17
18687,15,13
186911,15,7
18703,12,13
18713,10,13
187213,6,15
18738,3,10
18748,7,17
187511,17,12
187616,4,11
18774,5,4
187815,9,13
187915,5,10
188010,11,16
188113,13,13
18825,6,7
188314,11,8
188410,18,6
188513,6,5
188616,3,11
18876,3,4
18881,6,12
18895,5,15
189011,16,12
189111,14,18
189210,12,15
18938,3,7
189412,8,4
189515,13,7
189612,12,16
189713,11,16
189815,11,12
18999,6,6
19007,10,19
190114,12,15
190214,7,12
190317,9,9
19046,7,4
190515,8,10
19068,2,7
19075,16,8
19087,9,15
19097,7,3
191016,5,6
191112,11,14
191217,12,10
19135,5,7
191414,2,8
191511,15,2
19166,18,11
191710,18,7
19181,10,13
191915,12,3
192011,12,1
19216,3,8
19223,3,8
192312,9,2
19249,4,3
192511,2,9
19264,8,4
192711,5,6
192815,14,8
192910,11,2
19306,6,14
19316,3,5
19324,14,5
193310,12,16
193412,8,13
193516,8,6
19366,9,15
193712,19,10
193818,7,8
19397,5,2
19402,15,9
194114,12,13
19429,2,5
19437,18,7
19449,0,9
194513,15,12
19462,5,12
194714,13,10
194818,13,10
19499,15,2
195016,10,7
19517,4,17
19528,17,9
19539,14,14
19546,5,8
195512,1,12
19569,17,13
19574,6,13
19582,10,6
19599,14,4
19607,6,15
19613,15,13
19626,1,9
196311,15,6
196411,13,17
19658,14,2
196611,12,18
196717,11,4
196811,11,3
196915,17,12
19703,10,11
19712,11,8
19725,4,5
19738,2,6
19748,16,12
19757,15,3
19764,8,8
19776,9,1
197815,11,13
19793,4,6
19808,16,6
19817,8,16
19825,11,13
198314,12,17
198412,18,9
19854,11,9
198617,9,5
19877,18,6
198812,14,6
198915,11,9
19905,6,15
19917,16,10
199212,4,15
199311,17,8
199416,5,5
19959,3,8
19967,10,2
19978,1,10
199813,3,10
199911,10,16
200014,6,6
200111,4,5
200215,17,10
200311,14,15
200416,7,4
200512,1,8
20064,16,13
200710,2,7
200813,17,13
20094,14,16
20107,5,5
201114,6,16
20126,15,10
201315,14,11
20147,13,12
20156,5,16
20163,4,8
201716,9,9
20182,13,8
201910,4,16
202010,4,14
20215,9,9
20223,9,10
20231,8,9
20244,14,11
202511,8,15
202615,7,16
20275,7,14
20285,11,12
202910,14,13
203012,8,3
20314,14,4
203210,17,5
20339,7,15
20348,14,5
203511,16,13
20369,7,5
203715,5,4
203815,3,6
20399,18,13
20403,13,14
204115,11,6
204216,15,10
204313,15,10
20449,17,4
20455,12,17
20469,15,17
204712,12,18
204813,14,15
20499,13,17
205016,8,3
205115,6,3
205214,7,5
20534,17,8
205410,16,8
20559,9,1
205612,5,13
205712,5,6
diff --git a/day18/test_init.py b/day18/test_init.py
new file mode 100644
index 0000000..f8a4eaa
--- /dev/null
+++ b/day18/test_init.py
@@ -0,0 +1,24 @@
1# -*- coding: utf-8 -*-
2from aoc.datastructures import Coordinate3
3from day18 import Assignment
4
5
6class TestAssignment:
7 def test_open_sides(self):
8 blocks = {Coordinate3(0, 0, 0)}
9
10 assert Assignment.open_sides(blocks) == 6
11
12 blocks = {
13 Coordinate3(0, 0, 0),
14 Coordinate3(1, 0, 0),
15 }
16
17 assert Assignment.open_sides(blocks) == 10
18
19 blocks = {
20 Coordinate3(1, 1, 1),
21 Coordinate3(2, 1, 1),
22 }
23
24 assert Assignment.open_sides(blocks) == 10