Defribillators puzzle discussion


#186

‘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.


#187

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


#188

Nope, string.h is included.


#189

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.


#190

Yes, that was it! Thank you!


#192

[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.


#193

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.


#194

Objective-C
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.


#195

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?


#196

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];


#197

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() )


#198

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


#199

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?


#200

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


#201

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).


#202

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)


#203

nice hint, ty!


#204

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


#205

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.


#206

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.