Defribillators puzzle discussion


Why / 200.0 and *1000?


Hi guys,
little issue with this puzzle, when I am using ‘pi’ and ‘cos’ as requested it tells me it doesn’t exist…despite the “math import” at the beginning…
Thanks in advance


In Python?
How is the import written?


Yeah sorry, it’s in Python (not Python 3), and it’s written “import math”… I tried several time to refresh, didn’t change anything


Are you using math.cos?


No I didn’t try… should I you math.pi too then ?


Great it worked ! thank you !
I never had to use this way, does it work like this for every package ?


Yes, you can do, either:

import math


from math import cos,pi


Okay thank you for the explanation
So for example I could write my code normally and at the end, go back to the top of the code and do “from math import cos,pi” and it should work right ?
Thank you again guys !


You should write from math import cos,pi immediately even if you can write it everywhere in your code (before the use of cos and pi of course).


Hi! In C++, Like a lot of people here, I have complete all tests but I don’t have 100%.
For me, the problem is in the first test. I don’t know if the name is important but during the game the first test is “Example” and in the score page it is “Single possibility”.
I have used double or float, doesn’t matter. I have put << endl for the answer.
I don’t have other idea.


Does your code work if the information of only 1 defibrillator is provided in the game input?


To be sure, I tested to put “N = 1” before the loop to simulate only 1 defibrillator. It works.


Chingmann has helped me and it works. I forgot to convert degree to radian :slight_smile:


My C# code, which works fine in VS, isn’t returning the expected results on here.
After finnicking about for longer than I’d like to admit it turned out my numbers were off, though I beleive that I converted them correctly.
Am I being an Idiot?


Do you see that your second Console.WriteLine is the same as the first one? That means you have to fix the line between them.


Hint: string.Replace() does not act the way you think it does…


I already figured it out thanks to Chingmann. It was even more glaringly obvious in hindsight than usual and I’m stricken with shame. But such boorishly blatant blunders bare benefits, I will not make this mistake again.


I also had the problem, that the formula provided by the webpage listed in external resources is too precise!
Simple trig will do the deal and get you 100%

Here is the javascript:
function calculateDistance(user, defibrillator){
let distance = Math.sqrt(Math.pow(defibrillator.latitude - user.latitude, 2) + Math.pow(defibrillator.longitude - user.longitude, 2));
return distance;



I have a problem with my code.

My code is working only in 50% of cases.

Somebody can understand the reason?


import java.util.*;
import java.math.*;
import java.text.*;

class Solution {
    public static void main(String args[]) {
        Scanner in = new Scanner(;
        double lou = Double.parseDouble("," , "."));
        double lau = Double.parseDouble("," , "."));
        int n = in.nextInt();
        if (in.hasNextLine()) {
        int[] id = new int[n];
        String[] nam = new String[n];
        String[] add = new String[n];
        String[] pho = new String[n];
        double[] lon = new double[n];
        double[] lat = new double[n];
        for (int i = 0; i < n; i++) {
            char[] def = in.nextLine().toCharArray();
            int dle = def.length;
            int con = 0;
            String aux = "";
            for(int j = 0; j < dle; j++){
                if(def[j] != ';'){
                    aux += def[j];
                else if(con == 0){
                    id[i] = Integer.parseInt(aux);
                    aux = "";
                else if(con == 1){
                    nam[i] = aux;
                    aux = "";
                else if(con == 2){
                    add[i] = aux;
                    aux = "";
                else if(con == 3){
                    pho[i] = aux;
                    aux = "";
                else if(con == 4){
                    aux = aux.replaceAll("," , ".");
                    lon[i] = Double.parseDouble(aux);
                else if(con == 5){
                    aux = aux.replaceAll("," , ".");
                    lat[i] = Double.parseDouble(aux);
        double[] dis = new double[n];
        int mai = 0;
        for(int i = 0; i < n; i++){
            double x = (lon[i] - lou) * Math.cos((lat[i] + lau) / 2);
            double y = lat[i] - lau;
            double res = (Math.sqrt(x * x + y * y) * 6371);
            dis[i] = res;
            if(dis[i] <= dis[mai]){
                mai = i;

Call me in private.