summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--day15/__init__.py70
-rw-r--r--day15/example.txt14
-rw-r--r--day15/input.txt40
3 files changed, 124 insertions, 0 deletions
diff --git a/day15/__init__.py b/day15/__init__.py
new file mode 100644
index 0000000..3ba49d3
--- /dev/null
+++ b/day15/__init__.py
@@ -0,0 +1,70 @@
1# -*- coding: utf-8 -*-
2import re
3from abc import ABC
4from collections import namedtuple
5from dataclasses import dataclass, field
6from typing import Tuple, Iterator, Any, Set
7
8from aoc import BaseAssignment
9
10
11class Coordinate(namedtuple("Coordinate", ["x", "y"])):
12 def distance(self, other: "Coordinate"):
13 return abs(other.x - self.x) + abs(other.y - self.y)
14
15
16@dataclass
17class Sensor:
18 coordinate: Coordinate
19 nearest: Coordinate
20
21 def __post_init__(self):
22 self.radius = self.coordinate.distance(self.nearest)
23
24
25@dataclass
26class Map:
27 sensors: Set[Coordinate] = field(default_factory=set)
28 beacons: Set[Coordinate] = field(default_factory=set)
29
30
31input_pattern = re.compile("x=(-?[-0-9]+), y=(-?[0-9]+)")
32
33
34class Assignment(BaseAssignment, ABC):
35 def get_coordinates(self, line: str) -> Tuple[Coordinate, Coordinate]:
36 match = input_pattern.findall(line)
37
38 if len(match) != 2:
39 raise RuntimeError()
40
41 sensor_match, beacon_match = match
42
43 beacon = Coordinate(int(beacon_match[0]), int(beacon_match[1]))
44 sensor = Sensor(Coordinate(int(sensor_match[0]), int(sensor_match[1])), beacon)
45
46 result = tuple(Coordinate(int(x), int(y)) for x, y in match)
47
48 return result
49
50 def parse_input(self):
51 pass
52
53
54class AssignmentOne(Assignment):
55 example_result = 10
56
57 def run(self, input: Iterator) -> Any:
58 sensors = set()
59 beacons = set()
60
61 for line in input:
62 sensor, beacon = self.get_coordinates(line)
63 sensors.add(sensor)
64 beacons.add(beacon)
65
66 pass
67
68
69class AssignmentTwo(Assignment):
70 pass
diff --git a/day15/example.txt b/day15/example.txt
new file mode 100644
index 0000000..a612424
--- /dev/null
+++ b/day15/example.txt
@@ -0,0 +1,14 @@
1Sensor at x=2, y=18: closest beacon is at x=-2, y=15
2Sensor at x=9, y=16: closest beacon is at x=10, y=16
3Sensor at x=13, y=2: closest beacon is at x=15, y=3
4Sensor at x=12, y=14: closest beacon is at x=10, y=16
5Sensor at x=10, y=20: closest beacon is at x=10, y=16
6Sensor at x=14, y=17: closest beacon is at x=10, y=16
7Sensor at x=8, y=7: closest beacon is at x=2, y=10
8Sensor at x=2, y=0: closest beacon is at x=2, y=10
9Sensor at x=0, y=11: closest beacon is at x=2, y=10
10Sensor at x=20, y=14: closest beacon is at x=25, y=17
11Sensor at x=17, y=20: closest beacon is at x=21, y=22
12Sensor at x=16, y=7: closest beacon is at x=15, y=3
13Sensor at x=14, y=3: closest beacon is at x=15, y=3
14Sensor at x=20, y=1: closest beacon is at x=15, y=3
diff --git a/day15/input.txt b/day15/input.txt
new file mode 100644
index 0000000..e663ca5
--- /dev/null
+++ b/day15/input.txt
@@ -0,0 +1,40 @@
1Sensor at x=1112863, y=496787: closest beacon is at x=1020600, y=2000000
2Sensor at x=2980210, y=1712427: closest beacon is at x=2946825, y=1712605
3Sensor at x=2799204, y=1425283: closest beacon is at x=2946825, y=1712605
4Sensor at x=3999908, y=2754283: closest beacon is at x=4064129, y=2651511
5Sensor at x=760990, y=1455625: closest beacon is at x=1020600, y=2000000
6Sensor at x=3996490, y=3239979: closest beacon is at x=4064129, y=2651511
7Sensor at x=3347352, y=3603589: closest beacon is at x=3621840, y=3614596
8Sensor at x=2888433, y=2337157: closest beacon is at x=2946825, y=1712605
9Sensor at x=3423261, y=2191958: closest beacon is at x=3153728, y=1862250
10Sensor at x=1160237, y=3999960: closest beacon is at x=109153, y=3585462
11Sensor at x=693519, y=3701289: closest beacon is at x=109153, y=3585462
12Sensor at x=2615270, y=2824808: closest beacon is at x=2554122, y=2935074
13Sensor at x=3046971, y=1755494: closest beacon is at x=2946825, y=1712605
14Sensor at x=139591, y=1186912: closest beacon is at x=1020600, y=2000000
15Sensor at x=2309134, y=47090: closest beacon is at x=3211831, y=-792661
16Sensor at x=1849154, y=1377259: closest beacon is at x=2946825, y=1712605
17Sensor at x=2515971, y=2851853: closest beacon is at x=2554122, y=2935074
18Sensor at x=2524614, y=2738138: closest beacon is at x=2554122, y=2935074
19Sensor at x=3811778, y=1370280: closest beacon is at x=3153728, y=1862250
20Sensor at x=2615590, y=3819371: closest beacon is at x=2554122, y=2935074
21Sensor at x=3996286, y=3719213: closest beacon is at x=3621840, y=3614596
22Sensor at x=3963152, y=2368927: closest beacon is at x=4064129, y=2651511
23Sensor at x=3495504, y=3076982: closest beacon is at x=3621840, y=3614596
24Sensor at x=3725521, y=2560764: closest beacon is at x=4064129, y=2651511
25Sensor at x=952643, y=2385401: closest beacon is at x=1020600, y=2000000
26Sensor at x=3934384, y=2596106: closest beacon is at x=4064129, y=2651511
27Sensor at x=3060628, y=3082730: closest beacon is at x=2554122, y=2935074
28Sensor at x=3468382, y=3916817: closest beacon is at x=3621840, y=3614596
29Sensor at x=3300107, y=469364: closest beacon is at x=3211831, y=-792661
30Sensor at x=2306388, y=1932261: closest beacon is at x=2946825, y=1712605
31Sensor at x=1965, y=3514070: closest beacon is at x=109153, y=3585462
32Sensor at x=3081537, y=1841861: closest beacon is at x=3153728, y=1862250
33Sensor at x=2997643, y=1729779: closest beacon is at x=2946825, y=1712605
34Sensor at x=21714, y=3624181: closest beacon is at x=109153, y=3585462
35Sensor at x=1549467, y=3109269: closest beacon is at x=2554122, y=2935074
36Sensor at x=3722307, y=3839410: closest beacon is at x=3621840, y=3614596
37Sensor at x=3848580, y=3544878: closest beacon is at x=3621840, y=3614596
38Sensor at x=1189516, y=2153239: closest beacon is at x=1020600, y=2000000
39Sensor at x=468190, y=1889204: closest beacon is at x=1020600, y=2000000
40Sensor at x=270403, y=2762568: closest beacon is at x=109153, y=3585462