Skip to content

Instantly share code, notes, and snippets.

@danvk
Last active January 4, 2020 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danvk/72bb1111cdbc94f59e6e5cf5fbe44f63 to your computer and use it in GitHub Desktop.
Save danvk/72bb1111cdbc94f59e6e5cf5fbe44f63 to your computer and use it in GitHub Desktop.
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