Defibrillators puzzle discussion

Like most others here I pass the trial but when I got to validate I get a 77%, failing the first one, “Single possibility”. I’ve tried all the above suggestions, I even tried not converting to radians. I was already using doubles and I simplified the formula. It’s extremely frustrating. I’m using Java.

Any other suggestions especially since all others are completing.

I had the same problem, failing the “Single possibility” test. My approach was to set the distance of the closest defibrillator to an initial value of 10000 using the original formula and float precision. Then I updated that value while iterating though the list of defibrillators. I solved the problem by explicitly computing the distance to the first defibrilator in the list and starting with that value instead.

By now, I have noticed that my initial distance of 10000 was simply too low. I confused the radius of the earth with its circumference, a value of more than 50000 probably would have worked.

5 Likes

Did you ever find a solution to the 75% problem?

actually u just have to pass it for N=1 , just give some condition and u will get 100 % score.

1 Like

I am not getting passed any of the tests whatever I do, I tried all solutions in this topic.
Anyone got any ideas? this is the last excercise for 100% completed easy.

2 Likes

Try harder, read again the text.
Try with your pen and paper.

These are the results for the first test which is not correct!! even he distance for Hotel shows to be the shortest!
The answer should be maison

Name: Maison de la Prevention Sante
0.0677104433621504 0.761087970257301
Distance: 4867611361.46208
Name: Hotel de Ville
0.0680071451177145 0.760941387233069
Distance: 4867610896.95417
Name: Zoo de Lunaret
0.067611966262311 0.76165448221053
Distance: 4867613154.29005
Hotel de Ville

The distance code:

    double x = (b.longitude - a.longitude) * Math.Cos( (a.latitude + b.latitude) / 2.0);
    double y = b.latitude - a.latitude;
    return Math.Sqrt(x * x + y * y) * EARTH_RADIUS;

You know that (if you set EARTH_RADIUS to 6371) your output is showing distances of nearly 5 billions kilometers, right? Because it’s more than Sun to Neptune distance so there has to be something really wrong in your code.

I got 100% without 6731 const. C++ and using the numpunct do_decimal_point() and a getline with ‘;’ as sep.
Also, this task is also one pass and does not need to save the data to arrays.

Even my struct defib was completely unneeded because most parameters are unused, only the name, lat and lon.

For future users, I had the same problem, and it ended up coming down to how I was doing the math. Apparently the differing results only showed on this one Test Case (and both Complete Files when Submitting). Skip the radians and go with one of the simpler degree based formulas already listed on this page.

1 Like

So I’m using C for this puzzle. For debugging, I used printf to print out all of the DEFIB strings, just to make sure I’m getting them all. For some reason, I’m not receiving all of the strings. Is anyone else having this problem?

1 Like

I tried to solve this problem using C, PHP and JavaScript and every time I failed on test #2. Is there some bug with test files? Here is my distance calculator written in C.

EDIT: NO full code, small portion of code is acceptable, but it is not

Can anyone help?

No full code, please.

that is not full code, i don’t understand where is j variable from
UPD j - 2 = 4, j - 1 = 5
anyway, i couldn’t reproduce your solution

Here is how I calc j,for (j = 0; tokens[j] != NULL; j++); which ends up with that numbers (j - 2 = 4) and (j -1 = 5);

Anybody is getting work in PHP? I have not passed no one…

Hello all, I have a problem, my algorithm works fine on the two first tests, but doesn’t work on third and forth. It finds another solution than the one in out.txt, but when I take a look at the distance, the solution I find is still lower. I find CRR instead of the one in out.txt. Here is how I compute the distance

var x = (LON - lon) * Math.cos((LAT + lat)/2);
var y = (LAT - lat);
var d = Math.pow(x,2) + Math.pow(y,2); 

lon and lat are the longitude and latitude of the current defribillators.
Any ideas ?

EDIT : I’ve found, actually it was just a problem of replace, replace() had just replace the first comma and not all of them.

2 Likes

Somehow my test failed on Single possibility test (when submitting). I’m not quite sure how my code would handle 1 any different from 2 when all my checks are
for (int i = 0; i < N … that should always run once at least…I had to add a catch at the end for the case of 1 to pass that test, but that’s hacky…any ideas?

I have been struggling to write builtin bash solutions up to now… I shouldn’t have; it looks hardly possible here. I suppose that developpers of the game are not expecting us to simulate floating point arithmetics with bash builtin tools in the “easy section” ?
OR : am i missing something ???

Nobody said that you have to restrict to bash builtins… For example, for floating-point computations, bc is available.

But I agree with what will probably be your next remark, developing bash scripts with nothing but test scripts (and in particular no interactive console) feels… unnatural, at least.