There is that famous riddle:
A bear walks 1 km south, 1 km east and 1 km north, and comes to the place it started from. What color is the bear?
This one is very old, so I'll generalize it:
A bear walks
x
km south,y
km east andx
km north, and comes to the place it started from. This bear thinks that the North Pole is boring, so it never goes there. Which latitude did it start and end at?
Assume that the bear is an idealized point, and the Earth is a perfect sphere with 10000 km distance from the pole to the equator (however, you can use a more accurate model if it's easier for some reason).
Write a program or a subroutine that receives the two numbers x
and y
, and prints or returns the latitude.
Fine points:
- Input with at least 3 decimal places of precision should be supported
- Input is in the range (0...99999), bounds not inclusive
- If the situation is physically impossible, print an empty string or a message, or return an impossible value (like 91 or
NaN
- or, in fact, 90 - since 90 is an impossible value) - You should print the most northern (maximal) latitude that satisfies the conditions, except the North Pole. If the North Pole is the only solution, see above.
- Output precision should be like IEEE single precison or better (24 bits or 7 decimal digits of precision).
- If the output is printed, use decimal notation (e.g. -89.99 for a point near the South Pole) . If the output is returned, use floating-point or fixed-point notation.
Shortest code in bytes wins.
y
km east makes the bear return to the same place by doing an integer number of laps around? \$\endgroup\$y = 0
andx < 20000
are you expecting the largest representable number smaller than 90? What if that then gets formatted to 90 by theprintf
or equivalent? And what intermediate precision and accuracy is required? \$\endgroup\$