35
7
Given three sidelengths of a triangle, evaluate its aspect ratio AR given the following formula:
where
The closer to equilaterality a triangle is, the closer to 1
its aspect ratio is. The aspect ratio is bigger or equal to 1
for valid triangles.
Inputs
The input is three real positive numbers which can be encapsulated in a list or anything similar if need be.
Your program must output the same value no matter what the order in which the three sidelengths are inputted is.
Those three numbers will always be valid sidelengths of a triangle (degenerate triangles like one with sidelengths 1
, 1
and 2
will not be given as input). You need not worry about floating point inaccuracies when values become extremely close to a degenerate triangle (e.g. it is acceptable that your program would error division by 0
for input [1, 1, 1.9999999999999999]
).
The input can be given through STDIN
, as a function argument, or anything similar.
Outputs
The output is a real number bigger or equal to 1
with the standard accuracy that is acceptable in your language.
The output may be printed to STDOUT
, returned from a function, or anything similar.
Test cases
Inputs Output
1 1 1 1
3 4 5 1.25
42 42 3.14 ≈ 6.9476
14 6 12 1.575
6 12 14 1.575
0.5 0.6 0.7 ≈ 1.09375
Scoring
This is code-golf, so the shortest answer in bytes wins.
should s be (a+b+c)/3 ? – costrom – 2016-11-28T16:06:37.740
3
@costrom No, the formula is correct. s is the semiperimeter of the triangle. your formula would be undefined for an equilateral triangle.
– Fatalize – 2016-11-28T17:10:58.557Can I just get floats for input or do I need to get integers as well? – Erik the Outgolfer – 2016-11-29T13:35:48.193
@ErikGolferエリックゴルファー It is acceptable to input
42.0
instead of42
. – Fatalize – 2016-11-29T13:37:03.073@Fatalize Thanks. Also, can the inputs all be
0
? – Erik the Outgolfer – 2016-11-29T13:39:33.023@ErikGolferエリックゴルファー I fixed the description: "The input is three real positive numbers", so no input can be
0
(this would yield a degenerate triangle). Thanks. – Fatalize – 2016-11-29T13:41:55.233Is there a related Wikipedia or WolframAlpha page for this formula? – mbomb007 – 2016-11-29T15:00:15.767
@mbomb007 This formula is described in this book.
– Fatalize – 2016-11-29T15:13:25.100@Fatalize Yeah, I saw, but I was expecting to find more than that when searching. – mbomb007 – 2016-11-29T15:19:36.260
Input given through
STDOUT
? Do you meanSTDIN
, or do you actually want us to retrieve input throughSTDOUT
? – Zacharý – 2016-11-29T22:19:14.880@ZacharyT That was a typo, thanks. – Fatalize – 2016-11-30T07:34:41.860
@mbomb007 Look here.
– Adám – 2016-11-30T15:56:47.310Ehm. An answer in... MINECRAFT!?!?!. Ehm.
– RudolfJelin – 2016-12-02T18:58:08.417