2 of 8
embedded the linked image
algorithmshark
  • 8.8k
  • 2
  • 32
  • 55

Shortest code to sort walking points

The challenge is to, given a list of points, sort in a way that, when they are connected in this order, they never intersect.

Input format (read from stdin):

X Y
1 2
3 4
5 6
...

Output should be the same as input, but sorted.

Rules:

  • You can start from any point.
  • The last point must be same as first one, making a close circuit.
  • It should be done considering the Cartesian grid.

For further help:

diagram

Nacib Neme
  • 205
  • 2
  • 4