Temperatures puzzle discussion

Can you be more specific please? On which test? which language?

Have the same issue, I have tried faking the input with the data the validation tests use in the puzzle itself and I get correct results, but on submit I have all the tests with all negative numbers as failed :confused:

In my case it’s C#. All the tests that have only negative numbers as input

Yeah, you didn’t understand the subject:

Display 0 (zero) if no temperature is provided. Otherwise, display the temperature closest to 0, knowing that if two numbers are equally close to zero, positive integer has to be considered closest to zero (for instance, if the temperatures are -5 to 5, then display 5)

Read the bold part carefully. That mean that in your example the answers are -10 and -7. You dont have to revert the sign, the last sentence only applies when two numbers are equally close to zero.

positive integer has to be considered closest to zero

Does mean that 5 -5 -> 5 but if there are only negative numbers then -5 -5 -> -5

EDIT:
Plus, if you had clicked “submit”, you could have seen a hint:

It works when inputs contains only negative numbers: : {-15 -7 -9 -14 -12} -> -7 (250 pts)
When two temperatures are as close to 0, then the positive wins: {15 -7 9 14 7 12} -> 7 (750 pts)
It works with two negative temperatures that are equal: {-10 -10} -> -10 (250 pts)

2 Likes

Nice idea, terrific picture!
But I had some problems with the test routine: It seems to regard only the first position of the output! All your test cases have positive numbers lower than 10 as correct output, so this does not have any direct consequences.
But unfortunately your test cases do not cover all possible errors, so it would have been nice to have a full set of tests.
In my opinion, the following test cases are missing:

  • all temperatures are negative (correct code would fail with your current test routine)
  • temperature null is included (correct code would success with your current test routine)
  • lowest / highest possible temperature as only temperature (correct code would fail with your current test routine)
1 Like

The tests when you hit the ‘submit’ button are more complete:

It works when inputs contains only negative numbers: : {-15 -7 -9 -14 -12} -> -7 (250 pts)

it works with -273 alone (250 pts)
It works with 5526 alone (250 pts)

I may not be the full set of amwesome and hardcore tests, but it’s sufficient to see if you get the exercice. Plus remember that is it only an Easy puzzle, so i don’t think too much improvement are necessary, coz it will remain easy anyway.

1 Like

Bonjour,
J’essaie de passer ce puzzle en C++.
J’utilise strtok_r pour rĂ©cupĂ©rer les nombres dans le fichier.
Le problùme est que je me retrouve avec le message d’erreur suivant :

  • strtok_r was not declared in this scope

Dans le puzzle, il y a bien un include de STRING.

Est-ce que quelqu’un c’est dĂ©jĂ  retrouvĂ© avec le problĂšme?
Suis-je sur la mauvaise piste?

Merci d’avance.

#include <string> ou #include <string.h> ou #include <cstring> ?
Le premier ne doit pas inclure ce genre de fonction.
Les deux derniers oui (oui je sais, ça fait bizarre, mais le premier correspond Ă  la “string c++” alors que les deux autres permettent de rĂ©utiliser les fonctions string du C).

1 Like

je penses comme l’a dit @cup_of_tea, de base il n’y a que les include pour la classe std::string (qui soit dit en passant est largement suffisante pour ce puzzle).

Si tu tiens vraiment Ă  utiliser strtok et strtok_r, il faut suivre le conseil de @cup_of_tea et ajouter #include <cstring>

1 Like

OK merci pour cette information. Entre temps j’ai utilisĂ© la fonction FIND et j’ai eu 100%.
Encore Merci!! :slight_smile:

Bonjour,

J’ai fais l’exercice en java et lorsque je soumet mon code qui passe bien les tests j’ai deux points qui ne sont pas validĂ©s alors que les rĂ©sultats affichĂ©s sont les bon :

When two temperatures are as close to 0, then the positive wins: {15 -7 9 14 7 12} -> 7 (750 pts)

par exemple ce morceau c’est pas validé 

En tout cas merci pour ce site et bonne continuation !

La flÚche ne donne pas le résultat que tu as renvoyé, mais le résultat attendu.
Donc {15 -7 9 14 7 12} -> 7 veut simplement dire que la réponse est 7, mais pas forcément que ton code a affiché 7.

Les tests de validation diffĂšrent des tests utilisĂ©s pour les exemples sur l’ide. Il est donc simplement possible que le code soumis est faux, mais passe les exemples.

En effet,

AprĂšs vĂ©rification - et correction - j’avais fais des erreurs dans mon code mais il passait quand mĂȘme les tests de base, dĂ©solĂ© pour le dĂ©rangement et merci pour la rĂ©ponse ^^’

Pas de souci :wink:

True.

In my case, I updated the code to check the input only if N != 0.

I have a question, I am doing the code in C#,

my code fails on negative numbers because as I am about to give the answer, the code is incorrect because of the minus sign preceding the number.

Any workarounds around that?

I just don’t know why this happens.

What is the error exactly, can you give a small piece of your code here?

EDIT: code now deleted to let other users search

Here is my code, idk where is the error

The error is with the result is a negative number and I can’t understand why, hope someone can help me, I’ve made code way more complex than this and its killing me that I fail on something so simple xD

Have you read that? That probably is where you failed.

or that