Help me I'm lost in the ocean!
05AB1E, 13 12 10 bytes
Saved 2 bytes thanks to Emigna.
Since there is no trigonometric functions to be called using OP's assumption that the earth is locally a plane, it becomes possible to make an 05AB1E solution.
•1#oC•+¹*t
For understanding purposes input is referred to as 'h'
•1#oC• Push 12742000 [ = 2*R, where R is the radius of earth]
+ Compute 2*R+h
¹* Multiply by h. Result is (2*R*+h)*h
t Take the square root of it and implicitly display it
Try it online!
Python, 34 26 bytes:
(-8 bytes thanks to Osable!)
lambda i:(i*(i+12742))**.5
An anonymous lambda function. Takes input in kilometers and outputs in kilometers. Invoke as print(<Function Name>(<Input>))
.
PHP, 34 bytes
<?=sqrt((12742e3+$h=$argv[1])*$h);
breakdown
r^2+x^2=(r+h)^2 # Pythagoras base
r^2+x^2=r^2+2rh+h^2 # right term distributed
x^2= 2rh+h^2 # -r^2
x =sqrt(2rh+h^2) # sqrt
so far, this is identical to the old Mathematica answer
sqrt(2*6371e3*$h+$h*$h) # to PHP
sqrt(14742e3*$h+$h+$h) # constants combined
sqrt((14742e3+$h)*$h) # conjugation to save a byte
((14742e3+$h)*$h)**.5 # same size
now all that´s left to do is to add input =$argv[1]
and output <?=
- done