Defibrillators puzzle discussion

I appreciate the reply.

Well, I feel dumb. In java I was using substrings to replace the ‘,’ and then recreating a new string. Used string.replace and it worked like a charm.

Moral of the story: check your comma replacement.

Thanks ejKosa.

IMHO the provided formula must be changed to this simple one sqrt((x1-x2)^2+(y1-y2)^2) (thanks niskaz). The original one doesn’t even work with the big dataset.

ok, here is simple formula: https://upload.wikimedia.org/math/e/a/5/ea5c804eaead4c6b1c7bccdacd72603f.png, where theta is latitude and phi is longitude

for all the java users
there is a method in lang.Math called hypot(int x,int y)
this method calculates distances
so it is faster than calculating it yourself

this was very helpfull, thx man

Hi all,

Anyone facing issue with the first test case while passed the rest?

[Console output]

Maison de la Prevention Sante

Fail

Found: “Maison de la Prevention Sante”
Expected: “Maison de la Prevention Sante”

(Using C)

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.