Let's say you have a positive integer N. First, build a regular polygon, that has N vertices, with the distance between neighbouring vertices being 1. Then connect lines from every vertex, to every other vertex. Lastly, calculate the length of all lines summed up together.
Given the input N = 6, build a hexagon with lines connecting every vertex with the other vertices.
As you can see, there are a total of 6 border lines (length=1), 3 lines that have double the border length (length=2) and 6 other lines that we, by using the Pythagoras Theorem, can calculate the length for, which is
If we add the lengths of the lines together we get (6 * 1) + (3 * 2) + (6 * 1.732) = 22.392.
As structures with 2 or less vertices are not being considered polygons, output 0 (or
NaN, since distance between a single vertex doesn't make much sense) for N = 1, since a single vertice cannot be connected to other vertices, and 1 for N = 2, since two vertices are connected by a single line.
An integer N, in any reasonable format.
The length of all the lines summed up together, accurate to at least 3 decimal places, either as a function return or directly printed to
- Standard loopholes are forbidden.
- This is code-golf, so the shortest code in bytes, in any language, wins.
(Input) -> (Output) 1 -> 0 or NaN 2 -> 1 3 -> 3 5 -> 13.091 6 -> 22.392