Temperatures puzzle discussion

System.Linq.Enumerable+c__Iterator10`2[System.String,System.Int32]

got this error if i want to view it

Since it’s an array you have to do a foreach to see the content.

foreach (int i in array)
Console.Error.WriteLine(i);

ok got it…
Cant i use array[i] ?

Yes you can but you need to convert it to a list with .ToList();

Un problème que j’ai et qui est récurrent sur tout les puzzles proposé sur codingame et que je ne connait pas le type des input.
temps est-il une liste ?

Ce ne sont que des chaînes de caractères, les entrées n’ont pas de type particulier.

1 Like

Il semble y avoir un problème avec le 2ième test en PHP.
Tous les autres tests passent, et pour ce test particulier j’écris bien “-5” (la réponse qui est attendue", mais j’ai droit à un:

Echec

TrouvĂŠ : Rien
Attendu : Rien

Et quand je soumets, les validateur passent tous

Es tu sur de ne pas avoir un caractère invisible à la fin de ta chaine ?

Hello, above is my source code for this given problem.
The goal is to analyze records of temperature to find the closest to zero.

As you can see in the comments, how I was looking to solve the problem is read the data of integers stored in that string variable.

Then, separate them to find a minimum positive number and greatest negative number, then choose the one closest to 0.

Hi,

You have to use cerr to print debug message.

Then :

  1. You don’t handle positives temps as expected : integers ranging from -273 to **5526**
  2. You don’t output 0 if no temps.

You have to comment your debugs, or use “cerr” instead of “cout” to show them. (debugs: found, pmin, nmax)

And for the last test (0), you have to change your code to check this “special” case.

2 Likes

Ce problème s’appelle recherche dans une liste mais ce n’est pas une liste qui est fourni mais une chaine de caractère qu’il faut s’efforcer de convertir en liste … sans savoir comment est cette fameuse chaine.

Hi, I changed to above but still gave me the same error. I think i followed the requirement, and can’t really move forward.

Use cout to print output (and cerr for debug only)

cout << result << endl; //1

Then define your if(n == 0) result 0 outside the loop, because you overwrite result some line after the for-loop…

1 Like

Thanks! It worked now, and output matched.

Now i will move on to fix algorithm for case ‘0’.

Hi,

Working on the puzzle with Javascript. I am having difficulty accessing the ‘temps’ variable. It’s not in an array, and when I try to split it:

var n = parseInt(readline());
var temps = parseInt(readline());
var test = temps.split(’ ');

I get the following error:
TypeError: temps.split is not a function
at Answer.js.null on line 8

If it’s not an array and it’s not a string, I’m not sure how I can access the data. I tried printing the ‘temps’ variable to see if it shed any light, but doing so only resulted in one number:

print(temps);
Standard Output Stream:
1

Any suggestions?

use parseInt after split, not before.

That did it! Thanks magaiti.

Hey everyone, I am having trouble finding the best way to create Int variables to hold ints closestPositive and closestNegative. I am currently instantiating them with the constraints provided in the instructions, but my score is being marked down slightly for hard-coding the values.

int closestPositive = 5526;
int closestNegative = -273;

compare these against all values in the string
if newValue > 0 && newValue < 5526
closestPositive = newValue

etc.

But apparently I can’t declare a value for those variables myself…
I tried creating them in the loop, but the scope doesn’t reach the out statement at the end of the calculation.
Suggestions?

Is this your code in the loop? why do you compare to 5526 again? newValue < 5526 will be true for all values
=> you override closestPositive every time and at the end it will be just the last value in the input