# Defribillators puzzle discussion

#248

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.

#249

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.

#250

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).

#251

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.

#252

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

#253

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

#254

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

#255

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?

#256

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.

#257

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!

#258

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.

#259

what exception did you get?

#260

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.

#261

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

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.

#262

It rejects my solution saying it is hardcoded.
I id not hard code.
I donât even know what does that mean.

#263

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

#265

Try d = sqrt((xb-xa)^2 + (yb-ya)^2) instead of the âcomplexâ formula in the statementâŠ That worked for meâŠ

#266

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

#267

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

#268

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 ?