3
\$\begingroup\$

A regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length).

Your job is to find out if a given polygon is regular or not.

Specs

  • You will be given a list of Cartesian coordinate 2-tuples which describe the polygon's vertices.
  • The points will always make a valid polygon.
  • You have to return a truthy / falsey for whether or not the polygon is regular.
  • Assume vertices are rounded to the nearest int.
  • They might or might not be in order.
  • This is so shortest code in bytes wins!

Test Cases

Most test cases generated by this site.

[(1,2), (3, 2), (1, 0), (3, 0)] -> True
[(1, 1), (5, 3), (7, 7), (3, 5)] -> False
[(550,450), (455,519), (491,631), (609,631), (645,519)] -> True
[(106,81), (94,81), (84,88), (80,100), (84,112), (94,119), (106,119), (116,112), (120,100), (116,88)] -> True
\$\endgroup\$

closed as unclear what you're asking by feersum, Martin Ender Dec 7 '15 at 9:46

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Are the coordinates always integers? \$\endgroup\$ – Reto Koradi Dec 7 '15 at 3:59
  • \$\begingroup\$ Another question: Based on the examples, it looks like the vertices are not necessarily in order? \$\endgroup\$ – Reto Koradi Dec 7 '15 at 4:09
  • \$\begingroup\$ Surely a polygon with all integer coordinates cannot be regular unless it's a square? Are we assuming some rounding? \$\endgroup\$ – xnor Dec 7 '15 at 4:28
  • \$\begingroup\$ @xnor sorry forgot to mention, you're rounding to nearest int. \$\endgroup\$ – Maltysen Dec 7 '15 at 4:32
  • \$\begingroup\$ @RetoKoradi correct. they are in any order, updated question. \$\endgroup\$ – Maltysen Dec 7 '15 at 4:33

Browse other questions tagged or ask your own question.