Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

p10.py 1019B

il y a 5 ans
12345678910111213141516171819202122232425262728293031323334353637383940
  1. import itertools
  2. import math
  3. import sys
  4. def measure(start, other):
  5. dx, dy = other[0] - start[0], other[1] - start[1]
  6. angle = math.atan2(-dx, dy)
  7. return -math.pi if angle == math.pi else angle, math.hypot(dx, dy), other
  8. def seek(start, asteroids):
  9. pending = sorted(measure(start, ast) for ast in asteroids)
  10. while pending:
  11. copy = pending.copy()
  12. pending = []
  13. out = {}
  14. for angle, dist, ast in copy:
  15. if angle in out:
  16. pending.append((angle, dist, ast))
  17. else:
  18. out[angle] = ast
  19. yield list(out.values())
  20. text = sys.stdin.read()
  21. asteroids = {
  22. (X, Y)
  23. for Y, line in enumerate(text.splitlines())
  24. for X, cell in enumerate(line)
  25. if cell == '#'
  26. }
  27. visibility = {ast: len(next(seek(ast, asteroids))) for ast in asteroids}
  28. origin = max(visibility, key=visibility.get)
  29. print(visibility[origin])
  30. ordering = list(itertools.chain(*seek(origin, asteroids)))
  31. x, y = ordering[200 - 1]
  32. print(100 * x + y)