Defibrillators puzzle discussion

My statement has nothing to do with “interactive uses” vs “shell scripting”.
I also used bc to solve this exercise.
I use many GNU utilities like that on a (almost) daily basis, so (i) trying to solve these problems only with bash builtins seems somehow more challenging to me, and (ii) I was wondering if I was missing something big that makes the solution of this particular exercise possible with only bash builtins.

It is always possible, but it will probably not be easy, at the very least.

Restricting to builtins is very restrictive, you’ll probably end up rewriting useful CLI software yourself: simple things like sort, uniq, mktemp, as well as more powerful stuff like grep, sed, bc…

And then you will probably be blocked by performance issues on larger problems, if they are intended to be solved with the full /usr/bin toolbox. For example, what performances will your sort function have, when compared to the C implementation of /usr/bin/sort? Last time I checked, /usr/bin/sort was even faster than reading all the lines of a file in bash…

About emulating floating point computations with builtins, it shouldn’t be too painful, and that’s always a nice challenge of course. :wink:

And my point for interactive use was that it makes it harder to check what specific CLI helpers are here, what versions they have (for example, iirc, not all versions of sort can process floating point numbers), etc. Indeed I misunderstood your motivation.

A mi me pasa lo mismo. También he probado con considerar que el número ID esté en blanco y tampoco funciona.

Vale, para los que tengáis el problema con el Complet File 2 de SUBMIT:
Hay coordenadas sin comas. Puede que os encontréis con;
Latitude = 3

en vez de

Latitude = 3,012

por ejemplo.

Pensadlo cuándo tokenicéis.

Sorry, here we speak English, sometimes French.

No pasa nada, entiendo el inglés; el francés no mucho, sorry.
Encara que si vos va bé també sé xerrar es Mallorquí.
Ya me diréis como lo preferís. No me hagáis escribir en inglés pues el expresarme en este idioma no me va muy bien.

@miquelfs1981 like you don’t understand much french, we (at least me) don’t understand much spanish either. French is only tolerated when the topic begins with french because the website is french and is french translated.

But mostly, we use english here as a almost universal language, so if you can, please try to write in english.

Hi, everyone!
I’m trying to create internal class Defibrilator inside class Solution using Java. But compiler does not recognize it.
Please advice if I can create internal class in this game? If yes, what is properly signature?
Thanks!

p.s. here is code for internal class
Edit: Problem solved

I found!
There was missed double “ll” in constructor definition.

Hello,

I don’t thing if I have a problem with my calcul or not.
For the first test I found a distance of 5988.826002435874 for Maison de la Prevention Sante
But the smallest result is 5986.676330172809 for Hotel de Ville.

This my calcul

 

userLongitude = Solution.degreToRadian(userLongitude);
         userLatitude = Solution.degreToRadian(userLatitude);
         double distance = 0;
         double resX = (longitude - userLongitude) ;
         resX = resX * Math.cos((userLatitude + latitude)/2.0);
         double resY = (latitude - userLatitude);
         distance = (resX * resX) + (resY * resY);
         distance = Math.sqrt(distance);
         return distance * 6371;

longitude and latitude is already a radian. You thinks my problem is my calcul ?

1 Like

Guys pls help me i don’t know what the problem.
My code solved “example” and “exact position” tests correctly but then…
in complete file my answer was wrong:
CRR 43.60677900002087
Caisse Primaire d’Assurance Maladie 43.60677909943508
Caisse Primaire d’Assurance Maladie 43.60681094685711
min is CRR but the right answer is Caisse Primaire d’Assurance Maladie. I think it’s because of double operations.
thats my code:

double d = Math.sqrt((LON - longtitude) * (LON - longtitude) + (LAT - latitude) * (LAT - latitude));

1 Like

https://code.codingame.com/fileservlet?id=333750697029

1 Like

this formula isnt working too
I saw my formula in this topic right up

I can’t get Complete File 2 validated even though I hardcoded nothing… Is it because my code is too fast ?

I’m having trouble with this problem, I pass the example test, but fail the rest of them, and I can’t seem to find out why. My gut tells me it’s something to do with the dist function (distance formula) but I made sure the input was in radians! ( * PI / 180)

Any help is appreciated. Code is posted below in Ruby

include Math
$LON = gets.chomp.to_f  *  PI / 180 
$LAT = gets.chomp.to_f  *  PI / 180 
$N = gets.to_i

$LOC = []

# create array of defib locations
$N.times do
    $DEFIB = gets.chomp
    n = $DEFIB.split(";")
    #n.delete("")
    # subs "," in LONG and LAT to "."
    n[-1].sub!(",", ".")
    n[-2].sub!(",", ".")
    $LOC << n
end

##
# return distance between inputted positions
#
def dist(longA, latA)
    x = ($LON - (longA *  PI/180.0)) * cos(((latA *  PI / 180.0) + $LAT ) / 2 )
    y = $LAT - (latA *  PI / 180.0)
    return sqrt((x**2) + (y**2))
end

$dists = []

# create array of distances
$LOC.each do |x|
    $dists << dist(x[-2].to_f, x[-1].to_f)
end

$min = $dists[0]
# find smallest distance
$dists.each do |x|
    if x < $min
        $min = x
    end
end

# put smallest distance
puts "#{$LOC[$dists.rindex($min)][1]}"

i think that n is already an array after split, so in $LOC you get needed array of locations but N times

Tous mes test dans l’IDLE sont à 100% mais quand je fais envoyer il me note a 75% en précisant que le premier test n’est pas un succès alors que dans l’IDLE il est a 100% ??

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

LON = input()
LAT = input()
LON = float(LON.replace(",","."))
LAT = float(LAT.replace(",","."))
N = int(input())
min=1000
for i in range(N):
    DEFIB = input()
    fib=DEFIB.split(";")
    longB=float(fib[4].replace(",","."))
    latB=float(fib[5].replace(",","."))
    x=(longB-LON)*math.cos((LAT+latB)/2)
    y=latB-LAT
    d=math.sqrt(x*x+y*y)*6371
    if d<min :
        min = d
        nom = fib[1]
        
# Write an action using print
# To debug: print("Debug messages...", file=sys.stderr)

print(nom)

Note : C’est du python 3

Tu as peut-être oublié un cas bien précisé dans la consigne, j’ai à peu près le même code que toi.

Le seul qui est invalide est le premier avec une seule possibilité mais pourtant il a l’air de fonctionner à une possibilité ??

Cela veut dire que j’ai un test de plus.
Quand tu auras trouvé la solution, supprime ton code.