11
1
Introduction
Today I went fishing alone with my canoe, unfortunately I fell asleep and the stream brought me away, I lost my oars, now it's night and I am lost in the ocean! I can't see the coast so I must be far away!
I have my cell phone but is malfunctional because it got wet by the salty water, I can't talk or hear anything because the mic and phone speaker are broken, but I can send SMS to my friend who is on the coast's beach!
My friend has a very powerful torch and he raised it on top of bamboo's canes to show me the right direction, but I can’t row because I have no oars, so I must tell him how far I am so he can send someone to catch me!
My friend told me that he is keeping the torch at 11.50 meters on the sea level, and I can see the light right over the horizon. Now I only remember from the school that the Earth radius should be 6371 Km at the sea level, and I’m sittin in my canoe so you can assume that my eyes are at sea level too.
Task
Since the currents are moving me moment by moment, my friend is raising the torch from time to time (now it’s at 12.30 meters), please write a full program or function that will help me to calculate the distance from my friend’s position!
Here is a diagram (not to scale):
The orange point labelled M
is me, the red point labelled T
is the torch. The green line is the linear distance between M
and T
Input
Take from standard input the torch height h
in meters at the sea level, which I see right on top of the horizon, in the form of a floating point number with two decimals precision (with the accuracy of 1 centimeter or 0.01 meters), in the range from 0 to 100 included.
Output
You should return the euclidean length of the green line with the accuracy of 1 cm. For example if you output in meters, should be with two decimals (at least). The output can be either meters or kilometers, but respecting the accuracy.
Test cases:
All values in meters.
11.5 > 12105.08
13.8 > 13260.45
Rules
Shortest code wins.
Does the result have to be mathematically correct or is it ok if the first 2 decimals are ok? I mean that hxh is small in comparison to 2xRxh and can be neglected for small distances. (R is the radius of Earth and h is the height of the torch). – Osable – 2016-11-24T11:08:03.830
@Osable first 2 decimals are ok if you output in meters – Mario – 2016-11-24T11:21:47.123
What is the range of input? – Osable – 2016-11-24T11:27:32.983
@Osable you can consider the input to be from 0 to 100 (even too much than necessary/possible in this case). – Mario – 2016-11-24T11:36:59.573
Ok maybe h² is not that negligible within a centimeter if it goes up to 100 meters. – Osable – 2016-11-24T12:29:41.300
1You should have tried the Coast Guard Stack Exchange - code golferse can't help you get out of the ocean, man! – corsiKa – 2016-11-24T16:12:37.763
>
@PeterTaylor please see this Meta post
– Mario – 2016-11-25T08:52:21.250I've seen that meta post. I'm still waiting for an answer to my questions. – Peter Taylor – 2016-11-26T11:07:25.960
@PeterTaylor I edited the question adding explicitly all the specifications. – Mario – 2016-11-27T16:58:11.730