-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
##.###.#.......#.#....#....#..........#. | ||
....#..#..#.....#.##.............#...... | ||
...#.#..###..#..#.....#........#......#. | ||
#......#.....#.##.#.##.##...#...#......# | ||
.............#....#.....#.#......#.#.... | ||
..##.....#..#..#.#.#....##.......#.....# | ||
.#........#...#...#.#.....#.....#.#..#.# | ||
...#...........#....#..#.#..#...##.#.#.. | ||
#.##.#.#...#..#...........#..........#.. | ||
........#.#..#..##.#.##......##......... | ||
................#.##.#....##.......#.... | ||
#............#.........###...#...#.....# | ||
#....#..#....##.#....#...#.....#......#. | ||
.........#...#.#....#.#.....#...#...#... | ||
.............###.....#.#...##........... | ||
...#...#.......#....#.#...#....#...#.... | ||
.....#..#...#.#.........##....#...#..... | ||
....##.........#......#...#...#....#..#. | ||
#...#..#..#.#...##.#..#.............#.## | ||
.....#...##..#....#.#.##..##.....#....#. | ||
..#....#..#........#.#.......#.##..###.. | ||
...#....#..#.#.#........##..#..#..##.... | ||
.......#.##.....#.#.....#...#........... | ||
........#.......#.#...........#..###..## | ||
...#.....#..#.#.......##.###.###...#.... | ||
...............#..#....#.#....#....#.#.. | ||
#......#...#.....#.#........##.##.#..... | ||
###.......#............#....#..#.#...... | ||
..###.#.#....##..#.......#.............# | ||
##.#.#...#.#..........##.#..#...##...... | ||
..#......#..........#.#..#....##........ | ||
......##.##.#....#....#..........#...#.. | ||
#.#..#..#.#...........#..#.......#..#.#. | ||
#.....#.#.........#............#.#..##.# | ||
.....##....#.##....#.....#..##....#..#.. | ||
.#.......#......#.......#....#....#..#.. | ||
...#........#.#.##..#.#..#..#........#.. | ||
#........#.#......#..###....##..#......# | ||
...#....#...#.....#.....#.##.#..#...#... | ||
#.#.....##....#...........#.....#...#... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
f = open('d10.in', 'r') | ||
amap = [list(line.strip()) for line in f.read().strip().split('\n')] | ||
|
||
def hasObstacles(o1, o2): | ||
dx, dy = abs(o1[0] - o2[0]), abs(o1[1]-o2[1]) | ||
steps = max(dx, dy) | ||
if not steps: | ||
return True | ||
for i in range(1, steps): | ||
x = o1[0] + (o2[0] - o1[0])/steps*i | ||
y = o1[1] + (o2[1] - o1[1])/steps*i | ||
if x == int(x) and y == int(y) and (x,y) in objects: | ||
return True | ||
return False | ||
|
||
objects = [] | ||
M, N = len(amap[0]), len(amap) | ||
for i in range(M*N): | ||
x, y = i%M, i//N | ||
if amap[y][x] == '#': | ||
objects.append((x,y)) | ||
|
||
lines_of_sight = [] | ||
degrees = [0]*len(objects) | ||
for i in range(len(objects) - 1): | ||
for j in range(i+1, len(objects)): | ||
if (hasObstacles(objects[i], objects[j])): | ||
lines_of_sight.append((objects[i], objects[j])) | ||
lines_of_sight.append((objects[j], objects[j])) | ||
else: | ||
degrees[i] += 1 | ||
degrees[j] += 1 | ||
|
||
print('Part 1:', max(degrees)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--- Day 10: Monitoring Station --- | ||
You fly into the asteroid belt and reach the Ceres monitoring station. The Elves here have an emergency: they're having trouble tracking all of the asteroids and can't be sure they're safe. | ||
|
||
The Elves would like to build a new monitoring station in a nearby area of space; they hand you a map of all of the asteroids in that region (your puzzle input). | ||
|
||
The map indicates whether each position is empty (.) or contains an asteroid (#). The asteroids are much smaller than they appear on the map, and every asteroid is exactly in the center of its marked position. The asteroids can be described with X,Y coordinates where X is the distance from the left edge and Y is the distance from the top edge (so the top-left corner is 0,0 and the position immediately to its right is 1,0). | ||
|
||
Your job is to figure out which asteroid would be the best place to build a new monitoring station. A monitoring station can detect any asteroid to which it has direct line of sight - that is, there cannot be another asteroid exactly between them. This line of sight can be at any angle, not just lines aligned to the grid or diagonally. The best location is the asteroid that can detect the largest number of other asteroids. | ||
|
||
For example, consider the following map: | ||
|
||
.#..# | ||
..... | ||
##### | ||
....# | ||
...## | ||
The best location for a new monitoring station on this map is the highlighted asteroid at 3,4 because it can detect 8 asteroids, more than any other location. (The only asteroid it cannot detect is the one at 1,0; its view of this asteroid is blocked by the asteroid at 2,2.) All other asteroids are worse locations; they can detect 7 or fewer other asteroids. Here is the number of other asteroids a monitoring station on each asteroid could detect: | ||
|
||
.7..7 | ||
..... | ||
67775 | ||
....7 | ||
...87 | ||
Here is an asteroid (#) and some examples of the ways its line of sight might be blocked. If there were another asteroid at the location of a capital letter, the locations marked with the corresponding lowercase letter would be blocked and could not be detected: | ||
|
||
#......... | ||
...A...... | ||
...B..a... | ||
.EDCG....a | ||
..F.c.b... | ||
.....c.... | ||
..efd.c.gb | ||
.......c.. | ||
....f...c. | ||
...e..d..c | ||
Here are some larger examples: | ||
|
||
Best is 5,8 with 33 other asteroids detected: | ||
|
||
......#.#. | ||
#..#.#.... | ||
..#######. | ||
.#.#.###.. | ||
.#..#..... | ||
..#....#.# | ||
#..#....#. | ||
.##.#..### | ||
##...#..#. | ||
.#....#### | ||
Best is 1,2 with 35 other asteroids detected: | ||
|
||
#.#...#.#. | ||
.###....#. | ||
.#....#... | ||
##.#.#.#.# | ||
....#.#.#. | ||
.##..###.# | ||
..#...##.. | ||
..##....## | ||
......#... | ||
.####.###. | ||
Best is 6,3 with 41 other asteroids detected: | ||
|
||
.#..#..### | ||
####.###.# | ||
....###.#. | ||
..###.##.# | ||
##.##.#.#. | ||
....###..# | ||
..#.#..#.# | ||
#..#.#.### | ||
.##...##.# | ||
.....#.#.. | ||
Best is 11,13 with 210 other asteroids detected: | ||
|
||
.#..##.###...####### | ||
##.############..##. | ||
.#.######.########.# | ||
.###.#######.####.#. | ||
#####.##.#.##.###.## | ||
..#####..#.######### | ||
#################### | ||
#.####....###.#.#.## | ||
##.################# | ||
#####.##.###..####.. | ||
..######..##.####### | ||
####.##.####...##..# | ||
.#####..#.######.### | ||
##...#.##########... | ||
#.##########.####### | ||
.####.#.###.###.#.## | ||
....##.##.###..##### | ||
.#.#.###########.### | ||
#.#.#.#####.####.### | ||
###.##.####.##.#..## | ||
Find the best location for a new monitoring station. How many other asteroids can be detected from that location? | ||
|
||
|