Write a function to compute the total length of between all vertices of a regular polygon inscribed in a unit circle. For example, a square in a unit circle would have side length of
and each of the two diagonals would have a length of 2. Therefore, for
the total length is
. In the hexagon below, there are 6 lines of length 1 connecting adjacent points, 3 lines of length 2 connecting opposite points, and 6 lines of length
connecting points two away; therefore, for
, the total length is
.
Solution Stats
Problem Comments
7 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers8
Suggested Problems
-
1662 Solvers
-
1323 Solvers
-
514 Solvers
-
35 Solvers
-
554 Solvers
More from this Author321
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
The test suite seems suspicious to me. The length of the diagonals will add up to n, and the length of the edges will never be more than 2*pi*r = 6.28. Where are all the big values coming from?
"Diagonals" was confusing, so I changed the wording and added another example.
Oh, I see. The example of the square led me to believe that "diagonal" meant "diameter". Thanks for the clarification!
I am having precision problems with the first and third assert()'s in test 14. The relative precision on the first is about 1e-10 and it is getting a sum that is different by about 3 units. For the third, the error is much worse because if any of the elements of a() are off by even 1 unit, they don't trigger the isprime() and don''t get included in the sum.
I'm having the same problem as William: all tests pass except for test 14. I'm inclined to blame the test rather than my code (famous last words, I know).
OK, I reduced the number of terms in Test 14, and the three solutions submitted so far work.
Thanks, Chris!