Defibrillators puzzle discussion

There is an unprintable character after “Sante” (apparently with code 127).

@CG staff
Maybe the validator output could be improved to show such characters, like with cat -t.

Ok, I’m stuck, I pass all the test but the verificator refuse to pass “Complete file 2”…

In C you must add a \n at the end of the printf.

Hi guy, i have some probleme here, i can’t figure out why my code doesn’t work, it just doesn’t give the good result so it returns the wrong answer but i don’t know why :confused:

Exemple, for the first test, it gives me those result (distance; located name)
97.79845472658425; Maison de la Prevention Sante
99.68874161128257; Hotel de Ville
97.1710571235069; Zoo de Lunaret

I am working in javascript by the way.

Here is how i calcul the distance.
<------------------------------------ CODE ------------------------------------------->
conv = Math.PI / 180;
tmp = readline().replace(’,’, ‘.’).split(’;’);
tmp[4] = parseFloat(tmp[4]) * conv;
tmp[5] = parseFloat(tmp[5]) * conv;
x = ( tmp[4] - LON) * Math.cos((tmp[5] + LAT)/2);
y = (tmp[5] - LAT);
theOne[0] = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) * 6371;
<------------------------------------------------------------------------------------------>
LON and LAT are parsed in float.
I tried with and without the cos((LAT A + LAT B)/2)

thanks for your help

When I attempted this one in C++, I was in the group who passed the test cases 100%, but not the first validation one. Not the first/last line parsing issue.

What made it pass for me was to stop assuming defebrillators would be less than an earth radius distance away from the user’s position. That first case is probably some form of 0N 0E position. Or the distance formula is wrong.

1 Like

To me, the formula is concidering the fact that the earth is not a plan by the cos( some stuff) in it so I don’t understand what you say about the earth radius. Could you explain a little bit more please?

You saved me thanks.

Thats quite a shame that the formule they gave us doesn’t even work for their tests.

This post voluntarily spells things out in way more detail than is necessary. Don’t assume I’m making fun of you (or anybody), I just don’t know what level of understanding of my post you’re at, so I’m providing full detail.

I (and probably many others) keep track of the closest defibrillator found by remembering its distance to me in a variable. I update that variable as I evaluate other defibrillators. To keep the code nice and clean, that variable has a default value before it gets pitted against the defibrillators. (The common alternative is to single out one of them, say the first, but there are various reasons why it could be considered not as elegant)

The only safe practice is to use a quantity garanteed to be higher than all others to be considered in the problem. Like positive infinity. Unfortunately in many programming languages, infinity is not convenient to use as a value. So it’s quite natural to simply use a very high value.

I happened to use the earth radius. (I haven’t investigated it so much more deeply, but the symptoms are that) it worked in the IDE tests, yet failed in validation test #1. Using 1000 or 10000 (don’t remember) times the earth radius happened to make the test pass.

So my suspicion is that the test case uses coordinates way out of range for Montpellier. Surprising in context, but why not. Another explanation would be that the distance formula provided in the problem could be faulty. I haven’t checked anything more thoroughly, as I did validate the problem eventually. I was simply dropping a post here to give others who made the same “mistake” as me a chance to spare some debugging time.

2 Likes

Hello all!

I already passed all test but when I submit the result I only get 77% complete.
I miss the test: Single possibility for (250 pts)

I already tried to make a file with one single entry in Xcode (where I work) like for example:

3,879483
43,608177
1
49;CAP OMEGA;Rond point Benjamin Franklin MONTPELLIER;04 67 59 30 01;3,91427706121347;43,618609351242

And I get the correct output:
CAP OMEGA

Is there anything I can do to find what’s wrong with the code?
I’m using c++ with the formula provided:
double distance = sqrt(pow((LON_A-LON_B)*cos((LAT_A+LAT_B)/2),2)+ pow((LAT_A-LAT_B),2))*6371;

Thanks for the help

Do you use the same code online and offline, or have you changed your code to read the input from a file?

Yes, I change my code when I’m working offline to read the data from the file.

Offline all the tests worked perfectly.
Online I pass all the tests but after submit it continue to say: Failed --> Single possibility (250 pts) =(

Looks like test#3 (only when it runs in editor) is broken. It expects wrong answer. My solution passes all tests and scores 100% of Final score.

1 Like

Did you find the solution already?

I’m also stocked in the same problem: cannot pass the simple possibility

Maybe the bug is in the part you changed. Try the following. Take the code you use online and compile it. Then run your code from the command line and feed it the input file with myprogram < testcase.txt. This way you are testing the same code you use online.

I get error message when I try to test “Complete file”
There is nothing wrong in my code I test the rest and submit I get 100%
I think there is something wrong in “Complete file”

Yes, in your algorithm.

1 Like

thanks for the formula ! :smiley:

I just had a great frustration solving this one using C.
Just as KeeShenTan, I had unprintable characters in the names of some answers (test one and 4). I was able to delete the one in the 1st test using :

NOM[strlen(NOM)-1]='\0';

But that made 2nd and 3rd test fail because of missing real characters… So I sent my solution with test 1 and 4 failed, and it passed the “real” tests… Damn ! I’m happy but I passed so many time trying to solve those “input data failure”, maybe it should be corrected? That would be nice.

It seems including the radius of the earth in the formula causes incorrect calculation of the result and I can’t seem to figure out why.

While getting the correct distances in KM by inclusion of the radius of the Earth this causes the last two tests to fail, omitting the radius of the Earth allows completion of all tests but gives incorrect distance data, can someone explain what’s happening here? I’m not a math whiz so I’m having a hard time figuring out why this would be correct when the correct formula for KM is not, I’ve been working on it for hours and I can’t make sense of it.

In test 3:
CRR = 17.31516337125853
Caisse Primaire d’Assurance Maladie = 18.801879909040867
Andd I am at 100%