Indeed, the conversion has to be done not only for the cosinus ^^

# Defribillators puzzle discussion

**BrandonScriver**#146

I donāt understand whatās going wrong here:

```
double currLon = Math.PI / 180 * Convert.ToDouble(LON);
double currLat = Math.PI / 180 * Convert.ToDouble(LAT);
double lat = Math.PI / 180.0 * Convert.ToDouble(fields[4]);
double lon = Math.PI / 180.0 * Convert.ToDouble(fields[5]);
double x = (currLon - lon) * Math.Cos((currLat + lat)/2);
double y = currLat - lat;
double d = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) * 6371;
```

I keep getting Zoo de Lunaret as the result on the first test instead of the the correct result.

Where is my calculation going wrong?

**magaiti**#147

Beware: the decimal numbers use the comma (,) as decimal separator. Remember to turn the comma (,) into dot (.) if necessary in order to use the data in your program.

**BrandonScriver**#148

Thanks for that, I realized I didnāt do a replace on the initial position values (I was doing it on record values). It made a difference, but now Iām still stuck getting Hotel de Ville as the answer.

The relevant code looks like:

```
LON = LON.Replace(',', '.');
double currLon = Math.PI / 180 * Convert.ToDouble(LON);
LAT = LAT.Replace(',', '.');
double currLat = Math.PI / 180 * Convert.ToDouble(LAT);
DEFIB = DEFIB.Replace(',', '.');
string[] fields = DEFIB.Split(';');
double lat = Math.PI / 180.0 * Convert.ToDouble(fields[4]);
double lon = Math.PI / 180.0 * Convert.ToDouble(fields[5]);
double x = (currLon - lon) * Math.Cos((currLat + lat)/2);
double y = currLat - lat;
double d = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) * 6371;
```

Any ideas?

**SatineChatounette**#149

longitude is given before latitude, youāll have to switch your fields indices

**Kalenz**#151

Hello, I have a problem with this quest. I consider my algorithm well-working but the system says that the ācomplete file 2ā failed. Any ideas?

`Scanner in = new Scanner(System.in);

String LON = in.next();

String LAT = in.next();

int N = in.nextInt();

in.nextLine();

```
String result = "";
double distance = 999999999;
for (int i = 0; i < N; i++) {
String DEFIB = in.nextLine();
String[] elements = DEFIB.split(";");
double lon = Double.parseDouble(LON.replaceAll(",", "."));
double lat = Double.parseDouble(LAT.replaceAll(",", "."));
double longt = Double.parseDouble(elements[4].replaceAll(",", "."));
double lat2 = Double.parseDouble(elements[5].replaceAll(",", "."));
double a = (lat2+lon)/2;
double x = (lon - longt)*Math.cos(a);
double y = lat - lat2;
double d = Math.sqrt(x*x+y+y)*6371;
if(d<distance){
distance = d;
result = elements[1];
}
}
// Write an action using System.out.println()
// To debug: System.err.println("Debug messages...");
System.out.println(result);`
```

Thank you for any help

**knittingdev**#155

This saved me, thanks so much. Using the given formula was definitely why I was only getting 75%. Using this basic distance formula helped. *sighs* I knew that formula looked overly complicated for no reason.

**RainOfDelight**#156

Guys, Pleae help me. I have an error, and I really donāt understand what is the problem, someone pelase explain me what should I look for while debugging, the error is this :

ps. I am using c++ and to transfom the string to double I use stod(sting)

Aborted.

at raise.c. function __GI_raise (sig=sig@entry=6) on line 56

at abort.c. function __GI_abort () on line 89

at string_conversions.h. function __gnu_cxx::__stoa<double, double, char> ( __convf=0x401180 strtod@plt, __name=0x401eb9 āstodā, __str=0x614ec8 ā;Maison de la Prevention Sante;6 rue Maguelone 340000 Montpellier;04 67 02 21 60;3.87952263361082ā, __idx=0x0) on line 65

at basic_string.h. function std::stod ( __str=";Maison de la Prevention Sante;6 rue Maguelone 340000 Montpellier;04 67 02 21 60;3.87952263361082", __idx=0x0) on line 2889

at Answer.cpp. function get_lon ( a=ā1;Maison de la Prevention Sante;6 rue Maguelone 340000 Montpellier;04 67 02 21 60;3,87952263361082;43,6071285339217ā) on line 85

**magaiti**#157

shouldnāt it be obvious from the error message that you are trying to convert the wrong string?

**uchihamadarada**#158

I had this problem too. 1, 2 and 4th tests are passed, but 3rd failed. But when I submit my code, I had reached 100%!

**CeneezerPavlis**#159

I found that in some lines there are commas in the name or something, be sure to replace ALL commas (for 100% solution)

**frenzyx6**#160

Test (Exact Position) expects āCimetiere Saint-Etienneā. But there is no āCimetiere Saint-Etienneā in input.Can someone explaint that for me?

**frenzyx6**#162

So,then can someone help me? Canāt pass Exact Position. Maybe problem in this part(calculations)

DEFIB = DEFIB.split(ā ; ');

var x = ( LON * Math.PI / 180 - DEFIB[ 4 ] * Math.PI / 180 ) * Math.cos( ( LAT * Math.PI / 180 + DEFIB[ 5 ] * Math.PI / 180 ) / 2 );

var y = LAT * Math.PI / 180 - DEFIB[ 5 ] * Math.PI / 180;

var d = Math.sqrt( x * x + y * y ) * 6371;

if( d < min || min == 0){

min = d;

index = i;

}

**Multimodcrafter**#164

Oh goodness I just didnāt get the precision needed until i realized that i properly replaced the comma to a point on the defibrillators coordinates but NOT on my own positions coordinates *facepalm*.