Defribillators puzzle discussion


#228

They are given in degrees, not in radians.


#229

Awesome.
Lat/long are given in radians, not in degree as said MrAnderson

Thx!


#230

I found my mistake … it took me a while and so obvious !!!
I hate myself in these case :stuck_out_tongue:


#231

Bless u sir.


#232

[solved]
Hi,
I have got a mistake for test number 3…
I found nearest “Caisse d’assurance retraite et de la Sante au travail” (distance=0.0218670137907) than “Caisse Primaire d’Assurance Maladie” (distance=0.0329447601689)
the test #1 2 and 4 are ok but this doesn’t work…
I’m with python
Have you got an idea for my problem ?
Thanks a lot
I found the problem in my formula for distance.


#233

Hello tous le monde !

J’ai bien aimé ce puzzle mais je vous conseil de ne pas prendre la formule donné dans l’énoncé pour le calcul de distance car perso c’est ce qui faisait buger la pg…
Mais plutôt celle ci :wink:

d = R.acos(sin(a).sin(b)+cos(a).cos(b).cos(c-d))

Elle fait peur certe fonctionne très bien et le must c’est que cela se fait en une étape et pas trois !

a = Lat A
b = Lat B
c = Long A
d = Long B ----- Bien sur toutes ces données sont quand même a rentré en radians :wink:


#234

I had the same problem. don’t use the provided triangulation formula. Simplify it :

Sqrt((LON1 - LON2)^2 + (LAT1 - LAT2)^2)

That fixed may problems. I was using doubles in C#.


#235

JavaScript.

I have an issue where I pass all test cases in the IDE, but then when I submit I fail on “Complete file”. I can’t figure it out why. Is anyone here able to help?

const radCon = (180 / Math.PI)
const LON = readline().replace(',','.') * radCon;
const LAT = readline().replace(',','.') * radCon;
const N = +(readline());
let shortestDistance = Infinity;
let nameOfShortest = '';
for (let i = 0; i < N; i++) {
    let [,name,,, long, lat] = readline().split(';');
    long = long.replace(',', '.') * radCon;
    lat = lat.replace(',', '.') * radCon;
    x = (long - LON) * Math.cos((LAT + lat) / 2);
    y = lat - LAT;
    distance = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))
    if (distance <= shortestDistance){
        shortestDistance = distance;
        nameOfShortest = name;
    }
}
print(nameOfShortest);

#236

DO NOT forget to add “.0” at the end of numbers when computing with floats or doubles !


#237

The debugger in the browser doesent seem to want to replace commas with dots. So i cant parse the strings to doubles and my whole algorithm doesent work. Feelsgood when you cant even test your code.


#238

In Java, replace returns a new String, it doesn’t modify the current String.

https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replace(char,%20char)

actually, you can check the first pitfall of this playground: https://tech.io/playgrounds/1097/the-most-common-java-pitfalls


#239

Input values - that includes lat lng of User (first and second line of input) and not only - as I assumed - data for defribillators. Many minutes were lost :slight_smile:


#240

Thanks for the hint :slight_smile:


#241

Mate, you saved me so many hours here! Ty a lot!


#242

I dont get it inside the IDE all test work with sucess. when i submit the
“single possibility” test appear as Red. Why??? 0.o


#243

Strange…

In VS my code works correct, but in website - wrong.

Website cannot round a double value with many digits after ’ , '…
I’ve tried Math.Round, but it doesn’t work


#244

Bonjour,

j’ai fini l’exercice mais lorsque je soumets mes résultats, l’exercice n°3 n’est pas accepté.

J’ai changé mon code plusieurs fois mais rien ne change, pouvez-vous me conseiller?


#245

Well, the same old song - program passed all testcases in IDE, but failed on “Complete file 2” on Submit. I’ve tried all recomended - using different formulas, removing converting from degrees to rads, changing double to long double but nothing helped. And CG doesn’t give any clue what goes wrong. Thanks for killing my motivation


#246

Understand. It was timeout problem. After some optimization of my code (C++) it passed. But I still think, that CG should tell the type of error - e. g. “timeout error” or “wrong answer” or something like this


#247

I’m surprised that test set allow passing with wrong formulae. I’ve misspelled some part of it and was ok, other people simplify formula, some of them even overlook to convert to radians… Maybe add some test cases with points far away, to make errors be visible?