Temperatures puzzle discussion

Doing this in VB.net and for some reason my code fails on the -273/5526 only cases. I’m defining my closest temp immediately based on the original array string.

    Dim tempClosest, nextTemp as Integer  
    dim spaceAt as Integer   'Store the length of the string portion to extract'
    
    spaceAt = temps.IndexOf(" ") 

[EDIT: NO FULL CODE]

        Int32.TryParse(temps.Substring(0,spaceAt),tempClosest)
        temps=temps.Substring(spaceAt+1)

[EDIT: NO FULL CODE]

Any advice on why this isn’t actually succeeding on a singular string of -273 or 5526?

Hey, I resolved this puzzle and it works correctly,why it doesn’t display 100% done?

The same problem?
Are you getting the error “Hard coded” or similar?
If it was I’m searching for a solution too xD

maybe handling if n input is zero. it seems your code is okay. I’m gopher too. :smile:

It’s possible to resolve it in Objective C ?
Cause the temperature are allocated in char array, but this char array is populated with space, so impossible to success this algorithm without create another algorithm only for decompose the char array in real integer array.
Am i true ?

I haven’t tried it myself (because i suck at objectiveC) but supposedly all puzzles are achievable in all languages. Moreover you’re talking about parsing, which is the easiest part of every challenge here, and by easiest I mind the less tricky, so if there are performance issues for a challenge, it won’t be on the parsing.

Hi everyone, I’m going crazy…

Mi program passed successfully test cases 1, 4 and 6 (Simple case, Choose right temperature 2 and No temperature).

But for the other cases it return some ridiculous values and I can not find out why…

Thank you for your help.

[EDIT: NO FULL CODE]

Bonsoir j’ai passé tous les test avec succès mais le 2e test n’est pas validé lorsqu’on me donne le % de réussite alors que le correcteur de l’ide l’avait validé. Je n’ai pas du tout mis en dur. Cela m’affiche -273 alone en message d’erreur. Qqun peut m aider j’aimerai bien avoir le succès :slight_smile:

Convert С# solution to Javascript, pass all tests, but fail to submit -273 and 5526 only tests.
Cause Length and length not the same :(( and no warning for js in this case :((
// if (temps.Length > 0) {

Puisque mon programme ne fonctionnait pas a cause du fait que je ne comprend pas bien le type char (par exemple le minimum du test 1 je trouvais 32 parce que la liste que mon programme utilisait avait effectivement pour nombre plus proche de 0 le nombre 32, alors que la valeur a trouver est 1…) j’ai décider de changer le code donné par le jeu par cela :

//char temps[257]; // the n temperatures expressed as integers ranging from -273 to 5526
    //fgets(temps, 257, stdin); // the n temperatures expressed as integers ranging from -273 to 5526
    int j;
    int temps[n];
    for (j=0;j<n;j++) {
        scanf("%d", &temps[j]);
    }

mais il me semble que ce changement est un petit peu de la triche alors est ce que quelqu un a réussi a résoudre en C ce probleme en conservant le type char de la liste imposé par le jeu ?

Hi, I’m having some trouble with my code and I’m not sure what’s wrong with it. The language is PHP, see the code below:

fscanf(STDIN, "%d",
    $n // the number of temperatures to analyse
);
$temps = stream_get_line(STDIN, 256, "\n"); // the n temperatures expressed as integers ranging from -273 to 5526
$x = 0;
$z = 0;
if($n == 0){
    echo("0\n");
}
else{
    for($j=0; $j<$n; $j++){
        if($temps[$j] > 0){
            $tpos[$x] = $temps[$j];
            $x++;
        }
        if($temps[$j] < 0){
            $tneg[$z] = $temps[$j];
            $z++;
        }
    }

so in this part of the code, I try to split the array with temperatures in 2 other arrays, one made fully of positive temperatures and another made only of negative temperatures. Then I tried to sort out 1 value out of each array, and ultimately the value closest to 0 with the following:

> $minpos = min($tpos);
>     $maxneg = max($tneg);
>     $modmaxneg = -$maxneg;
>     
>     if($minpos < $modmaxneg){
>         echo("$minpos\n");
>     }
>     if($minpos == $modmaxneg){
>         echo("$minpos\n");
>     }
>     if($minpos > $modmaxneg){
>         echo("$maxneg\n");
>     }
> }

I tried this code on my local server (apache) and it worked ok with the first test case. Now trying it on the website, it returns this error:

> Warning: max(): When only one parameter is given, it must be an array in the answer code at line 29

Working around my code a bit, I noticed that the problem seems to be that the loop that defines the array with negative temperatures isn’t working, therefore the $tneg array doesn’t exist, thus the max function won’t work. Anyone knows why this is happening?

what is this:
“The following validators differ from the puzzle test cases to prevent
hard coded solutions. This is why you can have some fails here even if
all of the tests provided in the IDE have been successfully passed.”
and why is it doing this to me?

Hello,

I have an issue with test number seven on this puzzle. This test will use -10 -10
The answer seams to be -10
However, even if my answer is effectively -10, this test is KO.

I have validated my -10 answer by overriden the list got from cin by the one used in the test 7 to check the result.
What I am missing ? Any Idea ? (Coded in C++)

Well I tryed to hard code an exception to check if this is the attended answer. It did not work either…

I found my mistake. I had badly parsed the cin… My bad…

What’s the exact error, can you just put here the line throwing an error, i also did it in C# comfortably!

salut y’a t’il un problème avec Swift pour résoudre cette énigme? j’arrive pas a accéder au Array “temps”, alors qu’ en Javascript ca passe nikel.:pensive:

C’est parceque temps n’est pas un tableau en swist mais une chaine de caracteres. C’est aussi le cas dans d’autres langages. Tu peux convertir la chaine de characteres en tableau manuellement:

let n = Int(readLine()!)! // the number of temperatures to analyse
let temps = readLine()! // the n temperatures expressed as integers ranging from -273 to 5526
let intTemps = temps.characters.split{$0 == " "}.map(String.init)

Hi,
Please can anyone tell me,
In this puzzle do you need to get input by yourself or it is given by default i am coding in c.

The default code already get the input for you. In C, this is done with there four lines:

int n; // the number of temperatures to analyse
scanf("%d", &n); fgetc(stdin);
char temps[257]; // the n temperatures expressed as integers ranging from -273 to 5526
fgets(temps, 257, stdin); // the n temperatures expressed as integers ranging from -273 to 5526

So inputs are in n and temps.

1 Like