diff options
| -rw-r--r-- | day15/__init__.py | 70 | ||||
| -rw-r--r-- | day15/example.txt | 14 | ||||
| -rw-r--r-- | day15/input.txt | 40 |
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 -*- | ||
| 2 | import re | ||
| 3 | from abc import ABC | ||
| 4 | from collections import namedtuple | ||
| 5 | from dataclasses import dataclass, field | ||
| 6 | from typing import Tuple, Iterator, Any, Set | ||
| 7 | |||
| 8 | from aoc import BaseAssignment | ||
| 9 | |||
| 10 | |||
| 11 | class 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 | ||
| 17 | class 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 | ||
| 26 | class Map: | ||
| 27 | sensors: Set[Coordinate] = field(default_factory=set) | ||
| 28 | beacons: Set[Coordinate] = field(default_factory=set) | ||
| 29 | |||
| 30 | |||
| 31 | input_pattern = re.compile("x=(-?[-0-9]+), y=(-?[0-9]+)") | ||
| 32 | |||
| 33 | |||
| 34 | class 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 | |||
| 54 | class 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 | |||
| 69 | class 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 @@ | |||
| 1 | Sensor at x=2, y=18: closest beacon is at x=-2, y=15 | ||
| 2 | Sensor at x=9, y=16: closest beacon is at x=10, y=16 | ||
| 3 | Sensor at x=13, y=2: closest beacon is at x=15, y=3 | ||
| 4 | Sensor at x=12, y=14: closest beacon is at x=10, y=16 | ||
| 5 | Sensor at x=10, y=20: closest beacon is at x=10, y=16 | ||
| 6 | Sensor at x=14, y=17: closest beacon is at x=10, y=16 | ||
| 7 | Sensor at x=8, y=7: closest beacon is at x=2, y=10 | ||
| 8 | Sensor at x=2, y=0: closest beacon is at x=2, y=10 | ||
| 9 | Sensor at x=0, y=11: closest beacon is at x=2, y=10 | ||
| 10 | Sensor at x=20, y=14: closest beacon is at x=25, y=17 | ||
| 11 | Sensor at x=17, y=20: closest beacon is at x=21, y=22 | ||
| 12 | Sensor at x=16, y=7: closest beacon is at x=15, y=3 | ||
| 13 | Sensor at x=14, y=3: closest beacon is at x=15, y=3 | ||
| 14 | Sensor 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 @@ | |||
| 1 | Sensor at x=1112863, y=496787: closest beacon is at x=1020600, y=2000000 | ||
| 2 | Sensor at x=2980210, y=1712427: closest beacon is at x=2946825, y=1712605 | ||
| 3 | Sensor at x=2799204, y=1425283: closest beacon is at x=2946825, y=1712605 | ||
| 4 | Sensor at x=3999908, y=2754283: closest beacon is at x=4064129, y=2651511 | ||
| 5 | Sensor at x=760990, y=1455625: closest beacon is at x=1020600, y=2000000 | ||
| 6 | Sensor at x=3996490, y=3239979: closest beacon is at x=4064129, y=2651511 | ||
| 7 | Sensor at x=3347352, y=3603589: closest beacon is at x=3621840, y=3614596 | ||
| 8 | Sensor at x=2888433, y=2337157: closest beacon is at x=2946825, y=1712605 | ||
| 9 | Sensor at x=3423261, y=2191958: closest beacon is at x=3153728, y=1862250 | ||
| 10 | Sensor at x=1160237, y=3999960: closest beacon is at x=109153, y=3585462 | ||
| 11 | Sensor at x=693519, y=3701289: closest beacon is at x=109153, y=3585462 | ||
| 12 | Sensor at x=2615270, y=2824808: closest beacon is at x=2554122, y=2935074 | ||
| 13 | Sensor at x=3046971, y=1755494: closest beacon is at x=2946825, y=1712605 | ||
| 14 | Sensor at x=139591, y=1186912: closest beacon is at x=1020600, y=2000000 | ||
| 15 | Sensor at x=2309134, y=47090: closest beacon is at x=3211831, y=-792661 | ||
| 16 | Sensor at x=1849154, y=1377259: closest beacon is at x=2946825, y=1712605 | ||
| 17 | Sensor at x=2515971, y=2851853: closest beacon is at x=2554122, y=2935074 | ||
| 18 | Sensor at x=2524614, y=2738138: closest beacon is at x=2554122, y=2935074 | ||
| 19 | Sensor at x=3811778, y=1370280: closest beacon is at x=3153728, y=1862250 | ||
| 20 | Sensor at x=2615590, y=3819371: closest beacon is at x=2554122, y=2935074 | ||
| 21 | Sensor at x=3996286, y=3719213: closest beacon is at x=3621840, y=3614596 | ||
| 22 | Sensor at x=3963152, y=2368927: closest beacon is at x=4064129, y=2651511 | ||
| 23 | Sensor at x=3495504, y=3076982: closest beacon is at x=3621840, y=3614596 | ||
| 24 | Sensor at x=3725521, y=2560764: closest beacon is at x=4064129, y=2651511 | ||
| 25 | Sensor at x=952643, y=2385401: closest beacon is at x=1020600, y=2000000 | ||
| 26 | Sensor at x=3934384, y=2596106: closest beacon is at x=4064129, y=2651511 | ||
| 27 | Sensor at x=3060628, y=3082730: closest beacon is at x=2554122, y=2935074 | ||
| 28 | Sensor at x=3468382, y=3916817: closest beacon is at x=3621840, y=3614596 | ||
| 29 | Sensor at x=3300107, y=469364: closest beacon is at x=3211831, y=-792661 | ||
| 30 | Sensor at x=2306388, y=1932261: closest beacon is at x=2946825, y=1712605 | ||
| 31 | Sensor at x=1965, y=3514070: closest beacon is at x=109153, y=3585462 | ||
| 32 | Sensor at x=3081537, y=1841861: closest beacon is at x=3153728, y=1862250 | ||
| 33 | Sensor at x=2997643, y=1729779: closest beacon is at x=2946825, y=1712605 | ||
| 34 | Sensor at x=21714, y=3624181: closest beacon is at x=109153, y=3585462 | ||
| 35 | Sensor at x=1549467, y=3109269: closest beacon is at x=2554122, y=2935074 | ||
| 36 | Sensor at x=3722307, y=3839410: closest beacon is at x=3621840, y=3614596 | ||
| 37 | Sensor at x=3848580, y=3544878: closest beacon is at x=3621840, y=3614596 | ||
| 38 | Sensor at x=1189516, y=2153239: closest beacon is at x=1020600, y=2000000 | ||
| 39 | Sensor at x=468190, y=1889204: closest beacon is at x=1020600, y=2000000 | ||
| 40 | Sensor at x=270403, y=2762568: closest beacon is at x=109153, y=3585462 | ||
