# Defribillators puzzle discussion

#145

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

#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?

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

#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?

#149

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

#150

Ah, whoops! Thank you!

#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

#152

Conversion degrees -> radians is missing

#153

My code pass the tests even if I leave input coordinates in degree.

#154

apples + oranges

EDIT: also (x*x+y+y). are you even trying?

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

#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

#157

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

#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%!

#159

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

#160

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

#161

There is oneā¦ Scroll, there are lots of entries ^^

#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;
}

#163

At least, you forgot to change ā,ā by ā.ā

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