Temperatures puzzle discussion

That’s right, but JS is very permissive.

And that’s the first mistake, you are setting n to 0 here, you should always use === in JS to compare object.

2nd one: in for (var i = 0; n; i++), you will never enter that since n equal 0
3rd one: It’s an infinite look, if n > 0 because you will never reach the condition, I bet you wanted to write i < n instead of n.

4 incoming one, since you are using JS be careful when playing with string because “-2” < “-20” === true

I don’t understand French but I’ve been trying to get this challenge working on C and your code works for me - thank you. It helps me to understand better (I always prefer to get these challenges without help but I think this was really difficult on C)

May be that i don´t understand the systematic. I get never the chance to type in some temperature values. So may be i understand something wrong. My first test-programm was in javascript in the way:

var n = parseInt(readline()); // the number of temperatures to analyse
var i;
var tmin = 9999;
var tres;
var temps;
for (i = 1; i <= n; i++)
{
 // n Temperaturen eingeben  
 temps = readline(); // the n temperatures expressed as integers ranging from -273 to 5526   
 var tempABS = Math.abs(temps);
 if (tempABS <= tmin)
  {
      tmin = tempABS;
      tres = temps;
  }       
}
// Write an action using print()
// To debug: printErr('Debug messages...');
print(tres);

But i never get a prompt to put in number of values and the values. So may be i am totally on the wrong way. I would be happy for a hint how this “parseInt(readline())” statement is to implement in the code.

You can copy and paste your code into the puzzle IDE “code area”, or type your code directly there. Then click the “Play Testcase” button to try your code again a set of input.

1 Like

yes, but the special part where you type in the numbers of temperatures and the temperatures itself is the problem i don´t understand. Can you put this in a loop, or are these input-lines
var n = parseInt(readline()); // the number of temperatures to analyse
and
readline(); // the n temperatures expressed as integers ranging from -273 to 5526
fix and simulated input? I dont get any prompt to input anything.

All puzzles are designed to offer no prompt. All puzzles are designed to have several pre-defined inputs that you can trigger by clicking on the test button or the submit button.

I assume the architecture of this site is like that:
Once you pasted your code into the IDE and clicked a button to run it, your code will be uploaded to the server. The server will input data to your code and then check its output. The server will send back the results (pass or fail, debug messages, etc) to your browser. The readline() function reads data from the server. There is no way for you to key in anything real time.

If you really want to use your own data as input, you can use the “custom” tag to define the input and output (you define your own output), and then run the test to see whether your code produce a matching output. The logic is just the same. The server has some prepared input data. The code is uploaded and executed in the server. You finally see the execution result.

1 Like

Ok. So by example, it´s possible to use the given code
readline(); // the n temperatures expressed as integers ranging from -273 to 5526
in a for-next loop or whatever, and the input is coming without direct input automatically from the system, right?

Yes Itrata. You can rely on the stub as a starting point to code. Most of the time it will provide correct looping to read data from the system. You need to add in suitable codes after the readline() to handle the data - keep it, process it, whatever.
Welcome aboard to this maze of puzzles.

1 Like

Hi There!

I think I found a bug in the 2nd testcase (java). The input I get from the program is {-12, -5, -137, 5}.
First off, the testcase is called only negative numbers, but I do get a positive number. No biggie, the program should still be able to deal with that, but the problem is more is in the error I get when running the test case.
I get the following message: Failure Found: " 5" expected “-”.

Cheers!

The second test case is
3
-12 -5 -137

Wherever your program got the 5 from is the problem. Getting 4 numbers when the first line said there were only 3 should be an indicator.

1 Like

Hello, can you help me?

I have passe all test cases besides №2 “Only negative number”, i think there is a bug.

There is my code in C++

int main() 
{
    int n;
    cin >> n; cin.ignore();
    int min;
    for (int i = 0; i < n; i++)
    {
        int t; // a temperature expressed as an integer ranging from -273 to 5526
        cin >> t; cin.ignore();
        cerr << "temperature is " << t << endl;
        
        if (n == 0)
        {
            min = 0;
            break;
        }
        
        if ( min == 0 )
        {
            min = abs(t);
        }
        else if (min > abs(t))
        {
            min = abs(t);
        }
    }
    cout << min << endl;
}

There is the IO of second test case:
Standard Output Stream:
temperature is -12
temperature is -5
temperature is -137
5
Failure
Found: 5
Expected: -

Can you please explain me why we are expecting “-” (minus symbol) ?

1 Like

it expects the “-” character because the whole answer is “-5”

D’oh, thanks. I found the issue in my code. It was a late night

Are the two Python3 codes below different?

i = input() 
for t in i.split():  #code works fine

vs

for t in input().split():  #error occurs

Why doesn’t my “for” loop work if I did not define " i = input() " ?

I managed to solve 100% but I don’t understand why the error occurs.
Hope someone understands what I’m asking… Thanks!

bonjour
puis je avoir de l’aide pour le puzzle temperatures
merci

Je pense que ce fil en est rempli !

Bonjour,

J’ai un code VB.net qui passe sans problème tous les tests (y compris les cas limites : pas de températures, températures identiques mais signes opposés…) ; mais une fois soumis, les validations apparaissent en rouge comme si c’était faux. Il me paraît difficile d’'avoir “tout juste” aux tests et “tout faux” à la soumission, surtout avec un problème qui n’est pas très difficile d’un point de vue algorithme.

Pouvez-vous regarder plus en détail ? Merci

Hello Matthieu. This is due to the update of languages. Check this thread for more information.

On test case 7, Two negative temperatures that are equal: {-10 -10}. What should be expected output? I didn’t use array or do sorting.

Admin edit: no need to post your code

What’s the temperature closest to 0 between -10 and -10?