day6, part1 being painfully slow
This commit is contained in:
parent
a5d1167aec
commit
dbbf97c64d
@ -51,5 +51,17 @@
|
|||||||
"wrong": [],
|
"wrong": [],
|
||||||
"correct": 4996
|
"correct": 4996
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"6": {
|
||||||
|
"1": {
|
||||||
|
"wrong": [
|
||||||
|
4787
|
||||||
|
],
|
||||||
|
"correct": 4771
|
||||||
|
},
|
||||||
|
"2": {
|
||||||
|
"wrong": [],
|
||||||
|
"correct": 39149
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
74
day06.py
Normal file
74
day06.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
from tools.aoc import AOCDay
|
||||||
|
from tools.coordinate import Coordinate, DistanceAlgorithm
|
||||||
|
from tools.grid import Grid
|
||||||
|
from typing import Any, List
|
||||||
|
|
||||||
|
|
||||||
|
def fill_space(grid: Grid, coords: List[Coordinate], distance: int, sizecounter: List[int]) -> int:
|
||||||
|
filled = 0
|
||||||
|
|
||||||
|
for i, c in enumerate(coords):
|
||||||
|
for t in c.getCircle(distance, False, *grid.getBoundaries()):
|
||||||
|
if grid.get(t) == '.':
|
||||||
|
for tc in coords:
|
||||||
|
if tc != c and t.getDistanceTo(tc, DistanceAlgorithm.MANHATTAN, False) == distance:
|
||||||
|
grid.set(t, False)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
grid.set(t, i)
|
||||||
|
sizecounter[i] += 1
|
||||||
|
filled += 1
|
||||||
|
|
||||||
|
return filled
|
||||||
|
|
||||||
|
|
||||||
|
class Day(AOCDay):
|
||||||
|
inputs = [
|
||||||
|
[
|
||||||
|
(17, "test_input6_1"),
|
||||||
|
(4771, "input6")
|
||||||
|
],
|
||||||
|
[
|
||||||
|
(39149, "input6")
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_input_coordinates(self) -> List[Coordinate]:
|
||||||
|
return [Coordinate(x, y) for x, y in self.getInputAsArraySplit(", ", return_type=int)]
|
||||||
|
|
||||||
|
def part1(self) -> Any:
|
||||||
|
coords = self.get_input_coordinates()
|
||||||
|
grid = Grid(".")
|
||||||
|
for i, c in enumerate(coords):
|
||||||
|
grid.set(c, i)
|
||||||
|
|
||||||
|
size_counter = [0] * len(coords)
|
||||||
|
fill_dist = 1
|
||||||
|
while fill_space(grid, coords, fill_dist, size_counter) > 0:
|
||||||
|
fill_dist += 1
|
||||||
|
|
||||||
|
return max(size_counter) + 1
|
||||||
|
|
||||||
|
def part2(self) -> Any:
|
||||||
|
coords = self.get_input_coordinates()
|
||||||
|
grid = Grid()
|
||||||
|
for c in coords:
|
||||||
|
grid.toggle(c)
|
||||||
|
|
||||||
|
region_size = 0
|
||||||
|
for x in range(grid.minX, grid.maxX + 1):
|
||||||
|
for y in range(grid.minY, grid.maxY + 1):
|
||||||
|
this_dist_sum = 0
|
||||||
|
for c in coords:
|
||||||
|
this_dist_sum += Coordinate(x, y).getDistanceTo(c, DistanceAlgorithm.MANHATTAN, False)
|
||||||
|
if this_dist_sum >= 10_000:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
region_size += 1
|
||||||
|
|
||||||
|
return region_size
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
day = Day(2018, 6)
|
||||||
|
day.run(verbose=True)
|
||||||
50
inputs/input6
Normal file
50
inputs/input6
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
260, 78
|
||||||
|
42, 40
|
||||||
|
87, 276
|
||||||
|
219, 124
|
||||||
|
166, 137
|
||||||
|
341, 138
|
||||||
|
82, 121
|
||||||
|
114, 174
|
||||||
|
218, 289
|
||||||
|
61, 358
|
||||||
|
328, 164
|
||||||
|
279, 50
|
||||||
|
218, 107
|
||||||
|
273, 320
|
||||||
|
192, 349
|
||||||
|
354, 103
|
||||||
|
214, 175
|
||||||
|
128, 196
|
||||||
|
237, 67
|
||||||
|
333, 150
|
||||||
|
98, 260
|
||||||
|
166, 217
|
||||||
|
92, 212
|
||||||
|
55, 165
|
||||||
|
205, 138
|
||||||
|
321, 199
|
||||||
|
285, 148
|
||||||
|
217, 130
|
||||||
|
357, 319
|
||||||
|
160, 67
|
||||||
|
63, 75
|
||||||
|
345, 123
|
||||||
|
316, 220
|
||||||
|
41, 253
|
||||||
|
240, 245
|
||||||
|
201, 124
|
||||||
|
336, 166
|
||||||
|
95, 301
|
||||||
|
55, 181
|
||||||
|
219, 315
|
||||||
|
209, 237
|
||||||
|
317, 254
|
||||||
|
314, 300
|
||||||
|
242, 295
|
||||||
|
295, 293
|
||||||
|
285, 263
|
||||||
|
330, 204
|
||||||
|
112, 106
|
||||||
|
348, 49
|
||||||
|
81, 185
|
||||||
6
inputs/test_input6_1
Normal file
6
inputs/test_input6_1
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
1, 1
|
||||||
|
1, 6
|
||||||
|
8, 3
|
||||||
|
3, 4
|
||||||
|
5, 5
|
||||||
|
8, 9
|
||||||
Loading…
Reference in New Issue
Block a user