day10, FINALLY!
This commit is contained in:
parent
fbffd6e4fd
commit
59962502d5
2
day02.py
2
day02.py
@ -12,7 +12,7 @@ class Day(AOCDay):
|
|||||||
memory = self.getInputAsArraySplit(',', int)
|
memory = self.getInputAsArraySplit(',', int)
|
||||||
memory[1] = 12
|
memory[1] = 12
|
||||||
memory[2] = 2
|
memory[2] = 2
|
||||||
comp = IntCode(memory, 100)
|
comp = IntCode(memory)
|
||||||
comp.run()
|
comp.run()
|
||||||
|
|
||||||
return comp.memory[0]
|
return comp.memory[0]
|
||||||
|
|||||||
55
day10.py
Normal file
55
day10.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
from aoc import AOCDay
|
||||||
|
from coordinate import Coordinate
|
||||||
|
from grid import Grid
|
||||||
|
from typing import Any, List
|
||||||
|
|
||||||
|
|
||||||
|
def radarPing(grid: Grid, origin: Coordinate) -> List[Coordinate]:
|
||||||
|
angleList = {}
|
||||||
|
for asteroid in grid.getActiveCells():
|
||||||
|
if asteroid == origin:
|
||||||
|
continue
|
||||||
|
|
||||||
|
angle = origin.getAngleTo(asteroid, normalized=True)
|
||||||
|
if angle in angleList and origin.getDistanceTo(asteroid) > origin.getDistanceTo(angleList[angle]):
|
||||||
|
continue
|
||||||
|
|
||||||
|
angleList[angle] = asteroid
|
||||||
|
|
||||||
|
return [angleList[k] for k in sorted(angleList.keys())]
|
||||||
|
|
||||||
|
|
||||||
|
def getMaxAsteroidsSeen(grid: Grid) -> (Coordinate, int):
|
||||||
|
maxSeen = []
|
||||||
|
maxCoord = None
|
||||||
|
for check in grid.getActiveCells():
|
||||||
|
asteroids_seen = radarPing(grid, check)
|
||||||
|
if len(asteroids_seen) > len(maxSeen):
|
||||||
|
maxSeen = asteroids_seen
|
||||||
|
maxCoord = check
|
||||||
|
|
||||||
|
return maxCoord, len(maxSeen)
|
||||||
|
|
||||||
|
|
||||||
|
class Day(AOCDay):
|
||||||
|
test_solutions_p1 = [8, 33, 35, 41, 210]
|
||||||
|
test_solutions_p2 = [802]
|
||||||
|
|
||||||
|
def part1(self) -> Any:
|
||||||
|
grid = Grid()
|
||||||
|
for y, l in enumerate(self.input):
|
||||||
|
for x, c in enumerate(l):
|
||||||
|
grid.set(Coordinate(x, y), c == '#')
|
||||||
|
|
||||||
|
return getMaxAsteroidsSeen(grid)[1]
|
||||||
|
|
||||||
|
def part2(self) -> Any:
|
||||||
|
grid = Grid()
|
||||||
|
for y, l in enumerate(self.input):
|
||||||
|
for x, c in enumerate(l):
|
||||||
|
grid.set(Coordinate(x, y), c == '#')
|
||||||
|
|
||||||
|
asteroids_seen = radarPing(grid, getMaxAsteroidsSeen(grid)[0])
|
||||||
|
twohundreth = asteroids_seen[199]
|
||||||
|
|
||||||
|
return twohundreth.x * 100 + twohundreth.y
|
||||||
34
inputs/input10
Normal file
34
inputs/input10
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#....#.....#...#.#.....#.#..#....#
|
||||||
|
#..#..##...#......#.....#..###.#.#
|
||||||
|
#......#.#.#.....##....#.#.....#..
|
||||||
|
..#.#...#.......#.##..#...........
|
||||||
|
.##..#...##......##.#.#...........
|
||||||
|
.....#.#..##...#..##.....#...#.##.
|
||||||
|
....#.##.##.#....###.#........####
|
||||||
|
..#....#..####........##.........#
|
||||||
|
..#...#......#.#..#..#.#.##......#
|
||||||
|
.............#.#....##.......#...#
|
||||||
|
.#.#..##.#.#.#.#.......#.....#....
|
||||||
|
.....##.###..#.....#.#..###.....##
|
||||||
|
.....#...#.#.#......#.#....##.....
|
||||||
|
##.#.....#...#....#...#..#....#.#.
|
||||||
|
..#.............###.#.##....#.#...
|
||||||
|
..##.#.........#.##.####.........#
|
||||||
|
##.#...###....#..#...###..##..#..#
|
||||||
|
.........#.#.....#........#.......
|
||||||
|
#.......#..#.#.#..##.....#.#.....#
|
||||||
|
..#....#....#.#.##......#..#.###..
|
||||||
|
......##.##.##...#...##.#...###...
|
||||||
|
.#.....#...#........#....#.###....
|
||||||
|
.#.#.#..#............#..........#.
|
||||||
|
..##.....#....#....##..#.#.......#
|
||||||
|
..##.....#.#......................
|
||||||
|
.#..#...#....#.#.....#.........#..
|
||||||
|
........#.............#.#.........
|
||||||
|
#...#.#......#.##....#...#.#.#...#
|
||||||
|
.#.....#.#.....#.....#.#.##......#
|
||||||
|
..##....#.....#.....#....#.##..#..
|
||||||
|
#..###.#.#....#......#...#........
|
||||||
|
..#......#..#....##...#.#.#...#..#
|
||||||
|
.#.##.#.#.....#..#..#........##...
|
||||||
|
....#...##.##.##......#..#..##....
|
||||||
5
inputs/test_input10_1_0
Normal file
5
inputs/test_input10_1_0
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.#..#
|
||||||
|
.....
|
||||||
|
#####
|
||||||
|
....#
|
||||||
|
...##
|
||||||
10
inputs/test_input10_1_1
Normal file
10
inputs/test_input10_1_1
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
......#.#.
|
||||||
|
#..#.#....
|
||||||
|
..#######.
|
||||||
|
.#.#.###..
|
||||||
|
.#..#.....
|
||||||
|
..#....#.#
|
||||||
|
#..#....#.
|
||||||
|
.##.#..###
|
||||||
|
##...#..#.
|
||||||
|
.#....####
|
||||||
10
inputs/test_input10_1_2
Normal file
10
inputs/test_input10_1_2
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#.#...#.#.
|
||||||
|
.###....#.
|
||||||
|
.#....#...
|
||||||
|
##.#.#.#.#
|
||||||
|
....#.#.#.
|
||||||
|
.##..###.#
|
||||||
|
..#...##..
|
||||||
|
..##....##
|
||||||
|
......#...
|
||||||
|
.####.###.
|
||||||
10
inputs/test_input10_1_3
Normal file
10
inputs/test_input10_1_3
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.#..#..###
|
||||||
|
####.###.#
|
||||||
|
....###.#.
|
||||||
|
..###.##.#
|
||||||
|
##.##.#.#.
|
||||||
|
....###..#
|
||||||
|
..#.#..#.#
|
||||||
|
#..#.#.###
|
||||||
|
.##...##.#
|
||||||
|
.....#.#..
|
||||||
20
inputs/test_input10_1_4
Normal file
20
inputs/test_input10_1_4
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
.#..##.###...#######
|
||||||
|
##.############..##.
|
||||||
|
.#.######.########.#
|
||||||
|
.###.#######.####.#.
|
||||||
|
#####.##.#.##.###.##
|
||||||
|
..#####..#.#########
|
||||||
|
####################
|
||||||
|
#.####....###.#.#.##
|
||||||
|
##.#################
|
||||||
|
#####.##.###..####..
|
||||||
|
..######..##.#######
|
||||||
|
####.##.####...##..#
|
||||||
|
.#####..#.######.###
|
||||||
|
##...#.##########...
|
||||||
|
#.##########.#######
|
||||||
|
.####.#.###.###.#.##
|
||||||
|
....##.##.###..#####
|
||||||
|
.#.#.###########.###
|
||||||
|
#.#.#.#####.####.###
|
||||||
|
###.##.####.##.#..##
|
||||||
20
inputs/test_input10_2_0
Normal file
20
inputs/test_input10_2_0
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
.#..##.###...#######
|
||||||
|
##.############..##.
|
||||||
|
.#.######.########.#
|
||||||
|
.###.#######.####.#.
|
||||||
|
#####.##.#.##.###.##
|
||||||
|
..#####..#.#########
|
||||||
|
####################
|
||||||
|
#.####....###.#.#.##
|
||||||
|
##.#################
|
||||||
|
#####.##.###..####..
|
||||||
|
..######..##.#######
|
||||||
|
####.##.####...##..#
|
||||||
|
.#####..#.######.###
|
||||||
|
##...#.##########...
|
||||||
|
#.##########.#######
|
||||||
|
.####.#.###.###.#.##
|
||||||
|
....##.##.###..#####
|
||||||
|
.#.#.###########.###
|
||||||
|
#.#.#.#####.####.###
|
||||||
|
###.##.####.##.#..##
|
||||||
Loading…
Reference in New Issue
Block a user