Last active
January 4, 2020 00:23
-
-
Save danvk/72bb1111cdbc94f59e6e5cf5fbe44f63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def make_angle_map(station_loc, asteroids): | |
d = defaultdict(list) | |
x, y = station_loc | |
for a in asteroids: | |
ax, ay = a | |
angle = math.atan2(y - ay, ax - x) | |
d2 = (x - ax) ** 2 + (y - ay) ** 2 | |
d[angle].append((d2, a)) | |
for angle, pairs in d.items(): | |
d[angle] = [*sorted(pairs)] | |
return d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment