I finally got a 100% result score, but I am not happy with it. I have two issues with this puzzle, the first one being quite a serious one...
I use C# as my language of choice.
Issue 1 - Wrong latitudinal corrections in the submit-testcases!
The implentation of the formula for calculating the X-distance might have an issue. The formula contains of two parts:
- First, it should calculate the base X-distance on the equator by taking the difference of the longitudes, converting it to radians. (That result should be multiplied by the earth radius to calculate the real distance at the equator, but this might be optional, since in this puzzle relative distances are sufficient for comparison purposes.)
- Next, it should compensate the first result with the cosinus of the average latitude angle, because the distance between two longitude angles gets smaller when you move further away from the equator (to the north or the south).
Regarding this second (correctional) part, I suspect a bug in the submit-testcases. The cosinus function expects a parameter representing the angle in radians, but I received a 100% score only after I (wrongly) passed the angle parameter in degrees...!... In my opinion, this will actually result in very wrong latitudinal corrections, and thus in very wrong distances!
Issue 2 - Converting the string representations of longitudes and latitudes to their numeric values
As stated in the puzzle description, the comma's should be replaced with dots to be able to convert to numeric values.
As smart as I try to be, I tried an alternative route by using the TypeConverter class provided by the .NET Framework.
The following code runs correctly in my local Visual Studio installation, but fails with an exception in the online IDE:
string text = "3,1415926"; // note the comma!
var converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(double));
var culture = new System.Globalization.CultureInfo("fr-FR");
double value = (double) converter.ConvertFromString(null, culture, text);
Any clues why this code does not work in the online CodinGame IDE?
Thank you very much for your patience! Happy programming!