Defribillators puzzle discussion


#166

OMG! I just changed the order of user input and tests passed…god damn so many hours lost…


#167

I’m trying this problem in JavaScript and can’t get it to work. I’ve converted every latitude and longitude to radians, and I believe I’ve properly parsed out the numbers correctly (despite the commas).

var x = (lon2 - lon1) * Math.cos((lat1 + lat2)/2) var y = (lat2 - lat1) return Math.sqrt(x * x + y * y)
I’m using parseFloat to get the numbers after editing them in string form (using split and join). Am I losing precision here? I keep getting these numbers on problem two (I’m not multiplying by 6371 since it shouldn’t be necessary and still doesn’t work)
Centre municipal Garosud 0.014793827669153712 Cimetiere Saint-Etienne 0.01571963829676032

Apparently Cimetiere Saint-Etienne is the correct answer, but I keep getting Centre municipal Garosud. Any ideas?


#168

There are a lot of hints in this thread, have you read it? I know it’s long but there is a good chance you will find your answer here.
Trust me I passed this puzzle this very week after reading this thread.


#169

Hey!

So! My algorithm is good and output the good result, let me summarize what I did after calculating the distance I add it and the address to a list, then I sort the list based on the distancer and print the address of the smallest distance, however, in the 3rd and 4th test I failed, because the 2 tests wait for a result that don’t match mine, based on the stderr, my results are good (I printed every line and verified manually)…

If the inputs are from the REAL live website database, then it’s likely updated and the 2 tests are verifying with an old value from the database…

So the question here, did the inputs comes from the live website?


#170

Slightly more in-depth - http://andrew.hedges.name/experiments/haversine/


#171

Hey!

Did the game get inputs from the live database?

If so that maybe an issue.

My code seems to be good, but the 2nd & 3rd tests won’t pass, I got a result, but it’s not the one the puzzle creator set to be…

So, if the puzzle input from the live DB, the test cases maybe not good anymore…


#172

you have to resolve the puzzle using the standard input, not the live database.


#173

I am… Your reply confirms that the standard input of the puzzle is not the live DB but a static clone.


#174

Make sure to convert the longitudes and latitudes from degrees to radians. Also when doing your check to see if the distance is smaller than the current smallest distance make sure you are not checking if the smallest distance is equal to 0 when you have no smallest distances stored. You can do so by making the smallest distance -1 before any smallest distance is found and checking for that instead.


#175

I had to write my own parser since i’m using C. However it was surprisingly easy, and even more surprisingly fun! I encourage all of you to try it!


#176

Having trouble with this one. Is it a live DB? It seems to fail on a calculation that if made using Google maps help seems to be wrong.

3.874054
43.606779
0: 109
1: Caisse d’assurance retraite et de la Sante au travail
2: 29 cours Gambetta 34000 MONTPELLIER
3: 04 67 12 94 72
4: 3,87064343057042
5: 43,6068847626242
6: 0.00015351261620476814
0: 107
1: Caisse Primaire d’Assurance Maladie
2: 29 cours Gambetta 34000 MONTPELLIER
3: 04 99 52 54 49
4: 3,87110915929521
5: 43,6065196099402
6: 0.00036326676951972675
0: 110
1: Caisse d’assurance retraite et de la Sante au travail
2: Century 2 , 101 place pierre Duhem le millenaire 34000 MONTPELLIER
3: 04 67 12 94 72
4: 3,91465549573187
5: 43,6068978500869
6: 0.0005391628970360712
0: 108
1: Caisse Primaire d’Assurance Maladie
2: 90 allee Almicare Calvetti 34000 Montpellier
3: 04 99 52 54 49
4: 3,82126953167633
5: 43,6322018829039
6: 0.035422805723830414
Caisse d’assurance retraite et de la Sante au travail

Top two values are the initial lat/lon for the third test. the application is complaining that that it expects “Caisse P” and getting “Caisse d”. The one I’m returning is 109. I think it wants 107, but when I plug those values into Google maps, Caisse P is 200m while Caisse d is 190m. Am I missing something here?


#177

I compared my formula to this in forum, it seems be correct. But I get wrong results. Can someone tell me, what’s wrong?

static double getDistance(double loA, double laA, double loB, double laB)
{
    double x = (loB - loA) * Math.Cos((laA + laB) / 2.0);
    double y = laB - laA;
    
    return Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) * 6371;
}

The result is:
Dist:278749528586.599 Addr:Maison de la Prevention Sante
Dist:278746142778.745 Addr:Hotel de Ville
Dist:278762364357.738 Addr:Zoo de Lunaret
Closest Addr: Hotel de Ville

edit:
Ok, got it. Didn’t noticed that the user’s longitude and latitude include commas, too.


#178

Regarding my solution in python3:

My code fails to pass the “single possibility” test unless I hard-code the output being the first item’s address. Unfortunately I cannot debug the “hidden” tests, so I do not know where the error occurs. Even if I simulate a single correct input, it still passes any of the regular test cases.

This is my code with what I expect a “single possibility” test would look like:

lon = 3.879483
lat = 43.608177
defib = []
defib = defib.append('1;Maison de la Prevention Sante;6 rue Maguelone 340000 Montpellier;;3,87952263361082;43,6071285339217'.replace(',','.').split(';'))
'''
this means defib = [['1', 'Maison de la Prevention Sante', '6 rue Maguelone 340000 Montpellier', '', '3.87952263361082', '43.6071285339217']] and len(defib) = 1
'''
min = math.pi*6371
output = ''

for location in defib:
    x = (lon - float(location[4]))*math.cos((lat+float(location[5]))/2)
    y = lat - float(location[5])
    d = math.sqrt(x*x+y*y)*6371*(math.pi/180)
    if d < min:
        min = d
        output = location[1]

print(output)

This generates the output “Maison de la Prevention Sante” with min before being 20015.086796020572 and min after being 0.11662777224653707.

Yet, I fail at “single possibility” unless i hardcode the initial to output = defib[0][1]. Any clues? Maybe there is something with lists that I’m missing or the test case is a little buggy?


#179

Can someone tell me why am I getting this?
Answer.swift:59:14: error: cannot convert value of type 'String' to expected argument type 'Double'

Here’s line 59:
degToRad(Lat, b: b, c: Lon, d: d)

degToRad function declaration:
func degToRad (a: Double, b: Double, c: Double, d: Double) -> Double { //a is user lat //b is defib lat //c is user lon //d is defib lon .... }

b and d variable declaration:
var b: Double = Double(list[line][list[line].count - 1])! var d: Double = Double(list[line][list[line].count - 2])!

list is a bidimensional array with ‘sanitized’ values from DEFIB default variable, where each [line] is a defib.

Also, if any admins reading this, pls update swift to v3, or at the very least specify wich version is being used


#180

I think there is a problem with the 3rd test case, my php script didn’t passed it but got 100% when submitting.
Here is the error message when testing 3rd case :

Failure
Found: CR
Expected: Ca

But my script calculate those values :

CRR = 0.40642026791872
Caisse MSA Languedoc = 0.69070446831732

It seems that other people are having the same problem, maybe you should check that case ? Got me stucked for an hour but when submitting I got 100%.


#181

Did you convert the angles in radians?


#182

Would I get 100% when submitting if I didn’t ?


#183

If you do not make the conversion your distances mean nothing and they can’t be sorted correctly because function cos and sinus are not linear.
If cos and sin were linear your distances would be false but with a fixed error and their order would be correct.

The change can be made in 2 seconds so try it and you’ll tell us if you succeed, we can not say for sure that you would get 100% as we do not know what your code is.


#184

Friends, I spent a few hours until I was able to solve 100%. Be carefull! Error of the majority is that the “$LON and $LAT” also contain a number of coma. Respectively before you perform calculations necessary to convert them to numbers with a point.
Standard Output Stream:
’$LON = 3,874054’ must be '$LON = 3.874054’
’$LAT = 43,606779’ must be '$LAT = 43.606779’


#185

First time i calculate the value of y using latitudeA and latitudeB in radians and i solved two cases. When i calculate value of y in degrees then i solved all cases. I think that in description must be pointed that only for x latitude must be in radians, but who knows, maybe it’s only my mistake… Sorry my bad english…)