Defribillators puzzle discussion


‘strsep’ in this C implementation seems to be buggy, returning pointer values shifted by FFFF800000000000 upward. Had to compensate it by subtracting the deviation from all the ‘strsep’ return values.


I guess that you forgot to #include <string.h>


Nope, string.h is included.


Then, since strsep() is not standard C, you have to #define _BSD_SOURCE at the beginning, before the include. Alternatively, you can use strtok() instead.


Yes, that was it! Thank you!


[Removed the full code, please just show the useful part]

Can anybody have a look at this code please? I’ve been sitting here for hours and tests 2 and 3 keep failing.


Please don’t post your code in the forum.
Here you initialise your minimum distance to 0 so you just return the first defibrillator you read.


Is this a bug?
Simple example, I cannot get past a similar action.
NSArray *array = @[@“a”, @“b”, @“c”];
NSString *string = array[1];

This is the error I get:
/tmp/Answer.m:42:15: error: initializing ‘NSString *’ with an expression of incompatible type ‘NSArray’
NSString *string = array[1];
^ ~~~~~~~~
1 error generated.

It works in Xcode, posted similar question in the Chuck Norris challenge. Hoping to get more exposure. If the admins see this, can you replicate this, say if you hard code the solution for the first problem like this:
printf([@“Maison de la Prevention Sante\n” UTF8String]);

Many thanks, I want to be able to continue.


I don’t get it. I passed all tests except for Single possibility test case.

My code isn’t hardcoded at all. Any tips to pass it?


I figured out a solution to my question, posted here in case anyone else needs it.
NSArray *array = @[@“a”, @“b”, @“c”];
NSString *str = [array objectAtIndex:1];


I get the right output during playtest case #4 : complete file 2. But when I submit my program I get an error on that one.
(I use the fonction str.index() )


I also got the problem using PHP. No hardcoded solution, all 4 tests passed and still the “Complete file 2” validator fails. Frustrating.


I have tried two different forumulas in C++, which gave correct values and still the result was not ok in the validation tests. They expect addresses, which seem to way off than the minimums. WTF?


Is it Swift3 compliant ? or should I implement every low level functions such as readChar, putChar and replacingOccurrences etc… ?


After reading posts here, and thinking on it a bit, I remember that most distance comparison puzzles don’t need to take the square root, nor to multiply by any factor. Just use

d = x**2 + y**2

and compare those. This is much faster, and let me pass the submission test that I failed earlier. There’s a bit of a speedup by precomputing the constant for degrees to radians. And probably another speedup by estimating cosine (or dropping it completely).


If in final test you dont have 100%, that is becouse in some tests you dontt get success becouse time limit. So use similar formula,but more easier dist = sqrt((x1-x2) ^2 + (y1 - y2) ^ 2)


nice hint, ty!


You have to convert X, and Y to gradian.
it works for me.


Danger, Will Robinson!

The pythagorean theorem doesn’t work correctly when the x and y are latitude and longitude. Visualize what happens when you’re close to the North and South poles. You might luck out and get the right answer on this puzzle, but it’s absolutely the wrong way to do map distances.


Is there a wat to see why the second round of tests fails? My code checks out in the editor (all cases passed) but I keep failing one dataset during submission and I have no idea what could be causing it. Without knowing the cause of the error it’s pretty much impossible to debug.