···1111 return math.atan2(a[1] - b[1], a[0] - b[0])
121213131414-EPS = 1e-6
1515-1614# Read problem input
1715grid = []
1816asteroids = set()
···2725height = len(grid)
28262927# Part 1
3030-detections = {}
3131-3232-for y in range(height):
3333- for x in range(width):
3434- if not grid[y][x]:
3535- continue
3636-3737- p = (x, y)
3838- count = 0
3939- seen_angles = set()
4040-4141- for other in sorted(asteroids, key=lambda a: dist(p, a))[1:]:
4242- if angle(p, other) not in seen_angles:
4343- seen_angles.add(angle(p, other))
4444- count += 1
4545-4646- detections[x, y] = count
2828+detections = {
2929+ ast: len(set(angle(ast, other) for other in (asteroids - set(ast))))
3030+ for ast in asteroids
3131+}
47324833station, num = max(detections.items(), key=lambda x: x[1])
4934print "Number of detections:", num
···68536954# Rotate the queue to the starting angle
7055start = math.pi / 2
7171-while abs(queue[0][0] - start) > EPS:
5656+while abs(queue[0][0] - start) > 1e-6:
7257 queue.rotate(-1)
73587459# Iterate through the circular list, vaporizing the closest asteroid