Temperatures puzzle discussion

@Shlaf @RileyJin
Use the standard debug to analyse your errors. Print variables at different stages of your algorithm and I’m sure you’ll find your mistake in no time

Hi _CG_Thibaud, I’d love to use the standard debug system but i didn’t find it. I tried using the “Console.Error.WriteLine(“Debug messages…”);” but, as i suspected, it just pops the message “Debug messages” up.
Can you tel me how to use the debug system on codingame please, i’ve seek online with no sucess.

Anyway i’m still stuck here with a code that do something it is not suppose to (return 0 instead of 1).

It seems like evrytime i try to transform a negative into a positive number, it returns 0. Why the hell?!

Here is my code:

for (int i = 0; i < n; i++)
{
int t = int.Parse(inputs[i]);

        if (t<0)
        {
       
            Tableau[i]= -1*t;
        }
        else
        {
            Tableau[i]= t;
        }
       
        Array.Sort(Tableau);

Console.WriteLine(Tableau[0]);

so with 1, -2, -8, 4, 5 as inputs it should return 1, right?

I don’t code in C# but a quick (quicker than the time you took to write your message) google search gave me this:

Console.Error.WriteLine("Generating multiples of numbers from {0} to {1}", increment + 1, increment + 10);

So I’d try using something like that

Well as i said in my last comment i’m new in C#, so i’m sorry but i don’t see how this is suppose to help me.
I’ve tried using it, but i think i miss something.

Thanks anyway for trying to help.

I’m new in C# too, you know.

Ok, I went and try this

int t = int.Parse(inputs[i]); // a temperature expressed as an integer ranging from -273 to 5526
Console.Error.WriteLine("temp {0}", t);

and here’s what I got in the console:

temp 1
temp -2
temp -8
temp 4
temp 5
result

How does this sound?

Ok, so this shows me all the value of “t” during the loop. It could be usefull if i had no idea what values were input in the code.

Thanks for that tips, it’ll definitly be usefull on other circumstances. But here its not helping.

Just to be clear, i’m not here to get the solution of the exercise (i found it online). But to understand why my code keeps returning me 0.

Thanks again for trying :wink:

I think it can be useful here :wink:

Now that you know how to use the standard error, why don’t you check the values in your array “tableau” before and after sorting?
It could help to understand why it returns 0.

Thanks dude, it actually did help me figure out why it was returning 0.
The reason is that it was puting 0 as an input in my array “Tableau”.
So when i “Sort” it, the first value in Tableau is 0, ok that make sense.
But why the hell is there a 0 in my array.

Its not doing it with only negative numbers, its really confusing.
Any idea why?

When you initialize an array with a specific length in C#, every field will have it’s standard value. So if you, for example, initialize a new Array like this:
int[] table = new int[4];
It will look like this:
{ 0, 0, 0, 0 }
If you go into your for-loop and table[0] = 1;
Then your array will be { 1, 0, 0, 0 }
If you sort this, it is going to be { 0, 0, 0, 1 }
If you output table[0], it will return 0, because your 1 will be at position table[3] :wink:

1 Like

Yes i get that, thank you.

That is why i used “n” for my array:

int[] Tableau = new int[n];

“n” is the number of temperatur that i will have in my array

So evry single case in the array should have their own value of the input, none of them is 0.

And as i said its doing it only with positive numbers.

For exemple:
i have 5 temperatures, so it should look like this {1, 5, -8, -2, -5}
but here it is adding a 0 {1, 5, -8, -2, -5, 0} and that doesn’t make any sense for me

Try printing in debug all the content of your “Tableau” at every step of your algorithm.
You’ll see your mistake.

Finally found why!

It is the Array.Sort(Tableau) that was inside the loop, when i put it out of the loop it stopped adding 0 in the Array.
I don’t know why but its fixed now.

Thank you for your help guys :wink:

Well if you sort the array every time you add a value in it, you might overwrite values. Ex:

adding temp -1
[-1, 0, 0]
sorting
[0,0,-1]
adding temp -2
[0,-2, -1]
sorting
[0, -1, -2]
adding temps -3
[0, -1, -3]
sorting
[0,-1,-3]

Hi,

I am doing this puzzle in python3. I can’t seem to understand where the input for temperatures is.

I tried to print i and t, both output “5”. I tried printing i and t in a loop, but to no avail. Where is the value fo rthe temperatures?

Bonjour,
Pour ce puzzle, tous les tests passent mais je n’ai qu’un score de 63%.
Quand je soumets mon code, 3 nouveaux tests apparaissent en rouge mais n’apparaissaient pas à l’origine.
Est-ce normal ?
Merci,
David.

DURING the same loop as you read the temperatures (t), you may either store the values in a list for later processing, or process the values as you read them.

If you do nothing during the reading loop and try to print out the variables AFTERWARDS, you only get the last values of the variables of i and t because they will be kept overwritten by the newer values reached by i / assigned to t.

Hello David,

c’est expliqué juste au dessus des tests en rouge:

Les validateurs suivants diffèrent de ceux présents dans l’IDE pour éviter les solutions codées en dur. C’est pour cette raison que certains d’entre eux peuvent échouer même si la totalité des tests de l’IDE passaient.

Merci Thibaud,

Du coup, pour avoir 100%, il faut que mon code soit conforme aux 3 tests en rouge ?
Genre, je dois coder pour que ces 3 tests passent ?

Il faut et il suffit que tous les tests des validateurs passent.

To add some details, your code should be able to tackle all the different cases according to the rules of the puzzles. If your code validates every test in the IDE but not the validators, it means

  • either your code doesn’t handle an edge case which is not described by the IDE tests

  • or your code is “lucky” (outputting correct answer with wrong logic in IDE)