Defribillators puzzle discussion


#290

Bonjour.
je rencontre in problem assez bizarre avec la convetion des string en double en c++ pour exemple voici ce que j'obtients avec le premier test:
43.6071 latitude exact
3.60713 longitude avec erreur bonne valeur 3,87952263361082

43.5987 latitude exacte
3.59873 longitude avec erreur bonne valeur 3,89652239197876

43.6396 latitude exacte
3.63959 longitude erreur bonne valeur 3,87388031141133

je ne comprends pas ou est le problem


#291

CRR post

I had a problem with the third and fourth test. I got the wrong output no matter what formula I used.

I found out that the replace didn't replace all the comma for point. I used the replace on both the lattitude and longitude seperately and it work like a charm,


#292

All tests run finely for me, but after submitting the 3rd scenario doesn't work.
Anybody else has a same problem?


#293
  • Math.PI / 180

#294

use it cos (data)?, data = data* Math.PI / 180


#295

Thanks, now it works. But could you explain me why it was needed?


#296

In many (most) languages, the arguments for trig functions have to be entered in radians rather than degrees. Pi radians equals 180 degrees.


#297

Got the same case with the 75%.
Thank you for pointing me to the right way!
I just inited a distance with Infinity value -- seems it fit here the best


#298

Of course, Kristof! You takes data in degrees (LAN, LAT), but in general prog. language need it in radians to calcylate cos, etc. So you need to convert this argument so cos function works correctly. Otherway the result is wrong. In general, as we know from math, there are no big difference when cos calculates very low angles, plus you had same mistake in results (distances) what you compare, thats why the result of comparisation was often right. But, as you see, not alway =). I had almost same proble, cause I tried to convert vise-versa, from rad to grad. That was my strange mechanical mistake =)


#299

Hello,

I'm facing a problem. I'am coding in C#.
When i parse a string to double, then the comma disappears (While I should have a dot instead of the comma).

Exemple :

string LON = Console.ReadLine();
Console.Error.WriteLine("LON = " + LON); // 3,879483
double dLON = double.Parse(LON);
Console.Error.WriteLine("PARSE DOUBLE LON = " + dLON); // 3879483

I do not understand why that makes that, in Visual Studio it works !

Can you help me please ?


#300

Culture and regional settings must be different between CG and your machine.

This link suggests some solutions: https://social.msdn.microsoft.com/Forums/vstudio/en-US/a8b03023-7b0d-4a20-a4bd-a406f4e13cf3/converttodouble-problem-with-culture-and-regional-setting?forum=netfxbcl

Myself, I just did string.Replace before parsing.


#301

You are right.

I did :

double dLON = double.Parse(LON.Replace(",","."));
Console.Error.WriteLine("PARSE DOUBLE LON = " + dLON); // 3.879483

Thank you.


#302

I failed one of the tests when I was hard coding which character was the comma, and building the string around it. Once I switched out the string builder with replace it passed all the tests. So Iā€™m assuming one of the test cases has the comma in a different place than all the examples. Hope this helps someone out.