Temperatures puzzle discussion

Update: If I give a positive value it shows it expects “-”. If I give a negative value it show it expects “-5”… Maybe this way by design?

in the game temperatures, I have a string with some values:

1 -2 -8 4 5

how can I transformate it to a int array?
i don`t know hot to do it. If I knew it I would solve the problem, because I have the algorithm in my head, but I need a int array with the values.

What language are you running?

Hi this is why i got failure on test with negative numbers when the anwsere is correct:

“Found:
5
Expected:
-”
Can u fix it or should i hard code that one test?

1 Like

The answer seems to be negative.

thx now i noticed what is wrong :slight_smile:

Please help me with the code for Python

1 Like

Salut, salut ! Voila j’essaie de faire le puzzle température. En première version, je voulais rapidement tester le code ci dessous, même si je sais qu il ne peut pas résoudre le cas où 2 températures sont opposés. Le soucis c est qu il ne fonctionne pas dès le premier test, il m’affiche toujours 3 et je ne sais pas pourquoi !

Si vous pouviez m’aidé ça serait cool, merci tous le monde !

#include
#include
#include
#include
#include

using namespace std;

/**

  • Auto-generated code below aims at helping you parse

  • the standard input according to the problem statement.
    **/
    int main()
    {
    int n; // the number of temperatures to analyse
    int i;
    int result=0;
    int test;
    cin >> n; cin.ignore();
    string temps; // the n temperatures expressed as integers ranging from -273 to 5526
    getline(cin, temps);

    if (n!=0)
    {
    result=temps[0];

             for (i=1; i<n; i++)
                 {
                     test=temps[i];
                     if (test<result)
                         {
                             result=test;
                         }
                 }
     }
    

    cout << result << endl;
    }

Ton code ne donne que la plus petite température, pas la plus proche de 0.

I had been trying to use this site to get better at python and coding at general. The previous two easy puzzles had hints along with psuedo code which made it easier for me to grasp the ideas that the puzzle was asking for. Unfortunately I noticed the temperatures puzzle did not have the same hint function. I had been trying so hard to get all of the test cases to be correct but I would always end up with either one being incorrect, changing the code slightly and managing to make 3 incorrect. All this to say. I wish that the hint function was included on this one and on the other easy puzzles. It made it less frustrating and more fun/an actual learning experience.

2 Likes

Salut,

Merci de ta réponse :slight_smile:

  1. Alors d’une part, j’ai mal copié le code, la condition est en fait:
    if (abs(test)<result)

(Desespoir qui m a fait essayer plusieurs combinaisons possible.)

  1. D’autre part, même sans la valeur absolue, le code me ressort “3” alors que la réponse est “1”. Ce qui est vraiment bizarre.

Tu pourrais m’aider à comprendre pourquoi ?

Merci encore !

Tu peux m’envoyer ton code en privé si tu veux.

Same here. Please fix it :frowning:

@PhilStep Hi it was a problem in our code the anwsere is like -5 and we put there abs of it.

Yeah, just few minutes after posting I realised the same things :smiley:

Hello,

So I’m getting blocked with this puzzle and I am not sure if the problem is the puzzle itself or the language I am using. I am using python3 and I want to get the element i of temps. Thus, I am using the following code:

for i in range(n):
if(abs(temps[i]) < result_value):

But I get the following error:

bad operand type for abs(): ‘str’

For me it seems that the elements are a string instead of integers, as it is explained in the code. Can somebody help me to figure how to get the element i from temps?

You must translate the strings in integers in your temps list.

@nicolas_patrois do you mean like this?

if(abs(int(temps[i])) < result_value):

Because that is giving me another error:

invalid literal for int() with base 10: ’ ’

Just one point before finishing, temps is supposed to be an integer list:

temps = input() # the n temperatures expressed as integers ranging from -273 to 5526

Read carefully the filler code, you should read something like input().split().

Thank you @nicolas_patrois I have been able to solve the puzzle. Anyway I would recommend to add something in the description in order to show that the input data needs to be parsed before being able to calculate anything.