Defibrillators puzzle discussion

J’y penserais, merci ^^

I’m having trouble with the DEFIB-Array in C#.
I’m getting the Error CS0029: Cannot implicitly convert type string array' tostring’.
My Code so far is:

string[,] DEFIB = new string[N,6];
        for (int i = 0; i < N; i++)
        {
            for (int j =0; j < 6; j++)
            {
                DEFIB[i,j] = Console.ReadLine().Replace(",", “.”).Split(’;’);
            }
        }

Can’t find the problem. Thanks for your help!

Split returns an array, so you should write something like this:

DEFIB[i] = Console.ReadLine().Replace(",", ".").Split(';');

I tried that, but i still got the same message.

i bet you did not

and now you can’t see what i suggested you to try

you have a DEFIB array of array of strings, so DEFIB[i] is array of strings and DEFIB[i][j] is string
if you receive array of strings as a result of Split method you should assign it to correct data - DEFIB[i], which is array of strings

also, you don’t need j loop:

string[,] DEFIB = new string[N,6];
for (int i = 0; i < N; i++)
{
    DEFIB[i] = Console.ReadLine().Replace(",", ".").Split(';');
}

Sorry, I still don’t get it.
When I try your solution, I get the message, that I have the wrong number of indexes.
I also tried a jagged array ( DEFIB[][] ), but this isn’t working either.
Thanks for your patience! :wink:

    string [] namearr = new string [N];
    double [] lonarr = new double [N];
    double [] latarr = new double [N];
    
    for (int i = 0; i < N; i++)
    {
        string [] DEFIB = Console.ReadLine().Split(';');
        namearr[i] = DEFIB[1];
        lonarr[i] = Double.Parse(DEFIB[4].Replace(",", ".")) * (Math.PI / 180);
        latarr[i] = Double.Parse(DEFIB[5].Replace(",", ".")) * (Math.PI / 180);
    }

Ah, I understand! I try in this direction.
Thanks a lot!

Yes the Cos was my problem. Thank you! First 2 tests passed but not the 3rd one. :slight_smile:

I had the same problem and all I did to fix it and get 100% is removed radius of earth from their distance formula.

1 Like

Thank you ! I had the same problem as you. Tested a value more than 50 000 and it worked. Didn’t thought this extrem case could overcome.

Did you use the decimal format for calculating or did you use radians?

I’ve tried just about everything to get the single possibility to pass.
-try/catch block
-doubles -> floats
-setting initial distance of first defibrillator both name and distance value

My code is designed to iterate over each defibrillator site. If a calculation is found to be < the current shortest distance, the name is updated and so is the current shortest distance.

Short of trying to actually finding a way to see the input for a single possibility I’m out of ideas.

I stuck to degrees after checking this page.

Try to remove 6371, it’s a constant so it doesn’t affect the result, it just affects its scale. Likewise with the square root. it simplifies things.

Finally … I’m french but I use the site in english. And I initially disregarded the very important :
" Hint: Remember to turn the comma [,] into point [.], to use the data in your program."

lat=lat.replace(’,’,’.’);

1 Like

I appreciate the reply.

Well, I feel dumb. In java I was using substrings to replace the ‘,’ and then recreating a new string. Used string.replace and it worked like a charm.

Moral of the story: check your comma replacement.

Thanks ejKosa.

IMHO the provided formula must be changed to this simple one sqrt((x1-x2)^2+(y1-y2)^2) (thanks niskaz). The original one doesn’t even work with the big dataset.

ok, here is simple formula: https://upload.wikimedia.org/math/e/a/5/ea5c804eaead4c6b1c7bccdacd72603f.png, where theta is latitude and phi is longitude

for all the java users
there is a method in lang.Math called hypot(int x,int y)
this method calculates distances
so it is faster than calculating it yourself

this was very helpfull, thx man

Hi all,

Anyone facing issue with the first test case while passed the rest?

[Console output]

Maison de la Prevention Sante

Fail

Found: “Maison de la Prevention Sante”
Expected: “Maison de la Prevention Sante”

(Using C)