Defibrillators puzzle discussion

I’ve found my error, cosinus wasn’t exactly at the right place :slight_smile:

I did the same thing. I put toPrecision(5), completely randomly picked “5” and it went up to 100%.
Do you know why this works? I have no idea haha!

I have diferent problem, I get error because the input is not corect,
" ;Maison de la Prevention Sante;6 rue Maguelone 340000 Montpellier;04 67 02 21 60;3.87952263361082" "
rather to be radian value like this " 3.87952263361082 " I found error like this " Montpellier;04 67 02 21 60 ".
is missing double semicolon and number is wired, what it is? degree, minutes, seconds, miliseconds??

You forget do sqrt add to d = ((x2+y2)0.5) * 6371
I have d = sqrt((x
2+y**2)) * 6371
I didn’t know that this way also is posible " replace(’,’ , ‘.’) "

That’s always ‘inputs’/‘puzzles’/‘everybody’s but not mine’ fault…
All the tests are valids and about 54k coders have solved this puzzle.
If something is ‘missing’ it’s certainly because you don’t read it…

Great puzzle!
Thanks.

One note though.
I guess the current test cases pass even with longitudes and latitudes in degrees (not converted to radians). At least they did when I tried.

I don’t know if it’s possible to create a test case to block unconverted coords but that would be nice!

Cheers,
hypers

1 Like

Hello,
I did the puzzle in Python, and got a validation of 50% the first time, then fix some things and got 75% and then 100%.
The code worked with the data in degrees and in radians, but when I didn’t do the conversion the report increased from 50% to 75%.
Then, using the simplified formula (omitting earth’s radius) gave me the 100%.

My C++ version by the other hand looked really bad. Took me a lot of time to find a way to obtain the correct information from each defibrillator (using find_first_of)… and then changing the comma to point (also using find) and changing the strings to numbers by understanding how the stod/stof works. It was weird, sometimes I obtained a converted number that was not exactly the same of the string. The first characters following the comma/point were the same, but then they were others. Then I think that found the problem (defined the variable as double and performed a stof or the opposite, I think). Also I forgot to define the minimum distance used for the iteration as a double…
I didn’t understand why looking really so messy (compared with my python one, that is a lot shorter and look tidy), at the end, when I submitted it I obtained 100% without any validation problem.

1 Like

Thanks for looking! no, i didn’t use sqrt, i raised it to the 0.5, that’s the same thing. but i don’t know why it doesn’t work.

You need to convert the coordinates to radians before using them in your computations.
For example :
lon = input().replace(',','.')
lat = input().replace(',','.')
should be :
lon = (math.pi / 180) * float(input().replace(',', '.'))
lat = (math.pi / 180) * float(input().replace(',', '.'))

1 Like

thank you so much, this worked for me to get the 100%

SIX years ago I wrote my answer to this puzzle, and people still thank me for it. I really might consider it one of my greatest acheivements in life :smiley:

1 Like

Hi !

You have multiples errors in your code;

  • gotoNext :
    You didn’t check if you are at the end of the str, it is maybe why you segfault
  • char_to_double:
    You return atof of “a” but you move the pointer, so it will always be return atof("\0");
    You need to save the pointer in another variable and return atof of this variable

Hope it will help you :slight_smile:

Hi,

i think there is a problem in php:

for ($i = 0; $i < $N; $i++) doesn’t stop, it turn indefinetly, have any ideas?

wow, this made my day, been pulling my hair out over damn precision of a floating point number!

It seems to me that the formula for distance given in the description is wrong. My translation of that math into Kotlin:

val xd = lon -longitude *cos((latitude+lat)/2)
val yd = lat -latitude
return sqrt(xd*xd + yd*yd) *6371

Does that look erroneous to anyone? It did not get the accepted result. Here is the formula for distance that found the “correct” answer:

val xd = lon -longitude
val yd = lat -latitude
return xd*xd + yd*yd

Link to my solution
I think the Defibrillators puzzle should be reviewed by staff for correctness.

As said in the statement, longitude and latitude are given in degrees and the formula uses radians…

Tried solving this using python 3 and Test Case 3 is failing for me.

Some print Logs
CRR 0.0009248361751140284
Caisse Primaire d’Assurance Maladie 0.004527222322863614
Caisse Primaire d’Assurance Maladie 7.992925423047779

Test case is expecting Caisse Primaire d’Assurance Maladie but my solution reports CRR. All other test cases are passing.

CRR 0.0009248361751140284

There’s an issue in your formula somewhere, I get the following values :

CRR 0.4064202679186878
Caisse Primaire d''Assurance Maladie 0.23885270971148362
Caisse Primaire d''Assurance Maladie 5.103506714292043
2 Likes

Thank you @Djoums.
Found it. Im getting the product of the squares instead of the sum.

Got me too!