Defribillators puzzle discussion


I had the same issue and I was 100% that my code was good. After a while I found an error in my count_distance() formule. In my case it was the cosinus function, instead of dividing the lambda(latitude) I had cos(lambda(latitude)) / 2 :wink:
After change I have 100% score.


Please note. This also requires Degrees and not rads. It dont work with rads


Thanks, you’re the G, I didn’t think about having reversed it while filling my defib class.

I verified many times my formula and applied it in different ways but I still had this failing.

It now all passes.

Thanks bro


i’m stuck. What does Single possibility mean? I’m stuck at 75%.


I don’t fully understand the problem of replace, i used the same function but i don’t see the issue. Can you explain it further ?
Btw,I have the same problem(only the 2 first tests work and the distance is still correct)


Still same problem…
I can’t see the problem… here is my code if you can help :slight_smile:


OK, j’ai réussi, c’était juste ma méthode pour transformer la virgule en point qui ne marchait pas bien…


Hello everyone, Im new to programming and im trying to solve the defibrillators problem.
I will share my code to you so that i will get some help.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <float.h>
#include <math.h>

typedef struct defib {
    char *name;
    double lon;
    double lat;

double distance(double lon_a, double lat_a, double lon_b, double lat_b) {
    double x, y, d;
    x = (lon_b-lon_a) * cos((lat_a+lat_b)/2);
    y = lat_b - lat_a;
    d = (sqrt(x*x+y*y)) * 6371.0;
    return d;

double char_to_double(char *a) {
    while(*a!='\0') {
        if(*a==',') {
            *a = '.';
    return atof(a);

char *gotoNext(char c, char *str) {
    while(*str != c) {
    return str;

void getDefib(char *line, def *res) {
    line = gotoNext(';',line);
    res->name = line;
    for(int k=0;k<3;k++) {
        line = gotoNext(';',line);        
        *line = '\0';
    char *lon = line;
    line = gotoNext(',',line);
    *line = '.';
    line = gotoNext(';',line);
    char *lat = ++line;
    line = gotoNext(',',line);
    *line = '.';

int main(int argc, char **argv) {
    char strlon[50], strlat[50];
    int N;
    scanf("%s", strlon);
    scanf("%s", strlat);
    scanf("%d", &N);
    double lon = char_to_double(strlon);
    double lat = char_to_double(strlat);
    double min = DBL_MAX;
    char output[100];
    double d;
    char line[256];
    def res;
    for(int i=0;i<N;i++) {
        d = distance(lon,lat,res.lon,;
        if(d<min) {
    printf("%s\n", output);
    return 0;

And this is the output :
Segmentation fault.

at Answer.c. function gotoNext (c=59 ‘;’, str=0x7ffffffff000 <error: Cannot access memory at address 0x7ffffffff000>) on line 32

at Answer.c. function getDefib (line=0x7fffffffed13 “\033rvw\375\320x86_64”, res=0x7fffffffe7f0) on line 43

at Answer.c. function main (argc=1, argv=0x7fffffffeb08) on line 75

For some reason there is a segmentation fault that i cannot understand and i cannot solve for enough days.
Could somebody help me? I would higly appreciate your help.Thanks in advance.