Defibrillators puzzle discussion

In VS my code works correct, but in website - wrong.

probably thats because your system locale uses comma as decimal separator.
But for IDE you have to replace commas with dots. Alternatively you can specify the locale explicitly.

I had the same problem in python3. Since you do not really need the real distances, but only have to compare them, there is no need to multiply with any constant; even taking the square root is not nessessary.

You need to code a Dijkstra or A* algorithm so you need to calculate the square root (but not to calculate the real distance, proportional is OK).

If you are stuck at file complete 2, don’t use the formula given and conversion to radians. Just search on this topic the formula or on the web.

My problem actually is that input has different formats and I don’t know how to deal with it.

1 - 2;Hotel de Ville;1 place Georges Freche 34267 Montpellier;;3,89652239197876;43,5987299452849
2 - 1;Maison de la Prevention Sante;6 rue Maguelone 340000 Montpellier;04 67 02 21 60;3,87952263361082;43,6071285339217
3 - 76;Universite Montpellier 1 UFR Staps (Palais des Sports);;;3,84872346174789;43,6401970759746

May I have any hint? Thanks

Just solved that problem making 3 different kind of possible inputs, and treating them differently when splitting their strings. Finally, success!

that’s a phone number. Don’t bother with it; you should handle it as string (pointer to char, etc.)

Javascript
For the ffirst validator, here’s my code :
> if (N===1){

    print(defib[1]);
}
    print(defProche);

defib[1] equals to the name of the defebrilator
defProche equals to the nearest defebrilator, so in the firs case , they sould be equals.
But i print both of them and it still works .
And if i do this :

> if (N===1){
>          print(defib[1]);
>     }
> else{
>        print(defProche);
> }

it works too
how is it possible?

I know it’s been a while since you asked your question but I think your issue is that you have the latitude and longitude values reversed when you parsed the input line. I had similar distances in my calculations and I realized that was my problem.

Hello everybody.

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!

There is a problem with their input, usually the first line after the N is null so if you try split the first in.nextInt() you will get error, add a condition that checks if the string.equals("") and if its true you just skip that line.

what exception did you get?

Hello _CG_Thibaud. Thanks for your response.

I just tried to reproduce the exact exception, but I failed to do so. For some reason, the TypeConverter code now works fine! Great!

Regarding the cosinus issue
 I made a mistake converting degrees to radians. So now that code works fine too.

I have published my updated code and I have updated the puzzle rating from three stars to five.

Thanks again. :slight_smile:

1 Like

Bon je comprends pas. Tous les tests passent sauf le 3. Je trouve CRR au lieu de Caisse Primaire d’assurance maladie.

J’ai enlevĂ© les virgules des nombres et les ai remplacĂ©s par un point.
J’ai converti les angles en radians avec cette formule
radian= degree*(pi/180)

J’ai testĂ© toutes les formules de calcul de distance donnĂ©es dans le sujet et sur ce forum et CRR est toujours plus proche que Caisse Primaire d’assurance maladie.

It rejects my solution saying it is hardcoded.
I id not hard code.
I don’t even know what does that mean.
Please help

Regarde bien la liste des dĂ©fibrillateurs, je m’attendais Ă  ce que ça aille de 1 Ă  n par incrĂ©ment de 1 mais bizarrement, quand tu listes, ça passe du dĂ©fibrillateur 166 Ă  168
 Finalement quand tu print la longueur, ça te dit qu’il y a 167 dĂ©fibrillateurs alors que le dernier de la liste Ă  le numĂ©ro 189. Si tu ne le fais pas dĂ©jĂ , essayes donc plutĂŽt de tourner sur les numĂ©ros des dĂ©fibrillateurs plutĂŽt que sur un range de 1 Ă  n :wink:

Try d = sqrt((xb-xa)^2 + (yb-ya)^2) instead of the “complex” formula in the statement
 That worked for me


1 Like

OMG. It’s been hours since i’ve tried to figure out the same problem. Thank you !

Hello, this is a fairly generic question I think. My console output is not showing a large number of entries from my for loop. It jumps from defib 16 to 165. I’m pretty sure the program did work on all the entries between 16 and 165 since the closest defib updated but I would like to see those entries as well. Is there a UI setting I’m not familiar with?

Thanks

I’m trying to use these formula, and pass all tests , but just get 75% when i submit the code.
I didn’t pass the Complete file 2 


double d2r(double d) {
return (d / 180.0) * ((double) M_PI);
}

double r2g(double d){
return d * M_PI / 200.0;
}

double distance(const Position me, const Position side){
double x = r2g((d2r(me.lon)-d2r(side.lon)) * cos((me.lat + side.lat)/2.0));
double y = r2g(d2r(me.lat)-d2r(side.lat));
return sqrt(pow(x,2)+pow(y,2))*1000;
}

What’s wrong with my formula ?