Temperatures puzzle discussion

Test case 02 “only negative numbers” gives the following numbers as inputs:

-1, 2, -5, -1, 3, 7

First observation: These aren’t only negative numbers!

Secondly for some reason the validator says it was expecting -5.

Isn’t -1 the number closest to zero?

Is there a bug in the test case validator?

It seems to be checking the output character by character. I’m having a similar issue I think.

OK so after using the split method in python I was able to advance…

I find this puzzle to be very frustrating for beginners because if they don’t know about the split method they’ll try to devise one of their own…

I don’t feel like I made productive use of my time trying to solve this particular puzzle.

Hello, I’ve an issue with the C++ code linked to the temperatures. From the batch of test proposed, all test cases are correct but when I tried to submit my code, 2 test cases failed but I don’t have any traces in order to find what’s wrong with my c++ code.
The one linked to the min and the max.

[Removed the truckload of spaces]

When you declared a variables to the min, you have to add a value too…
Let it be a real temperature value, even if it is a minus… :wink: without math.abs… or something like this.

Hi.
Many (including me) thought that we get string from witch we must get numbers. Pretty confusing.

Bonjour,
J’ai une question concernant les validateurs, je n’ai que le 3eme de non validé : “5526 alone”.
Qu’est-ce qu’il signifie ? Merci pour vos réponses.

There is only one temperature?

I’m confused, shouldn’t we be considering that the values given might not be integers, what if there are invalid data in the input string? It’s a string after all not an int.

If I simply split the string by " " then I am assuming each entry is valid, am I not?
I get that we “know” the values are ints, but in the real world, we can’t be sure.

I don’t think that the split method is the best thing to use here, as you are assuming the inputs are valid Integers, and there are other ways.

It wants you to use only negative numbers out of the set of numbers.

I have a problem submitting my solution to this exercise.
It has been written in Java language.
One variable seems to have a correct value, when i try to access it through println, but the tests fail anyway with the following error :
"error: cannot find symbol
if(absActualTemp < absPreviousTemp) {
^
"

Here is the source code :

StringTokenizer st = new StringTokenizer(temps, " ");
List<Integer> temperatures = new ArrayList<Integer>(n);
int previousTemp = Integer.parseInt(st.nextToken());
int actualTemp = Integer.parseInt(st.nextToken());
int absActualTemp = Math.abs(actualTemp);  
int absPrevioustemp = Math.abs(previousTemp);
int result = previousTemp;
if (n == 0) {result = 0; }
for (int i=0;i<(n-1);i++) {
    if(absActualTemp < absPreviousTemp) {
        result = actualTemp;
    } else if(absActualTemp == absPreviousTemp) {
        if (Integer.signum(actualTemp) > 0) {
                   result = actualTemp;
        }
    }
    previousTemp = actualTemp;
    absPreviousTemp = absActualTemp;
    actualTemp = Integer.parseInt(st.nextToken());
    absActualTemp = Math.abs(actualTemp);
}

Thanks

This isn’t “the real world”. This is an exercise. In the context of this exercise, you can be assured that the inputs follow the input specification. There is nothing wrong with trusting that the inputs are as described.

The puzzles have a data contract. In “the real world” you need to be prepared for a data provider to possibly break the contract. Here, the input is static and has already been tested by thousands of people before you. If the input doesn’t adhere to the contract, then you should complain to CG, and they will fix it. In “the real world”, you would need to somehow handle bad data. Here, you can just yell loudly and move on to another puzzle until it’s fixed.

  • danBhentschel

absPreviousTemp != absPrevioustemp

Hi Vazul,

I’ve the same issue in javascript, and i get the same score too. Can you reproduce this test cases inside the code editor? i think, maybe the -273 alone test case contain and empty space or some character (maybe the integer that you are expecting is not a number), so if you’re using some kind of split method, this test cases cannot pass.

Sound crazy?

Cheers!

Yes it does.
Why don’t you begin with writing a program that can pass tests as simple as the following, instead of making bogus assumptions?

It seems to be lacking a test case where there are positives and negatives, and a negative is the answer. Every test seems to have only positives, only negatives, or if they’re mixed, the answer is always positive.

Eg. (7 -2 14 -7 22)
Correct answer here would be -2. You could have code that returns 7 or -7 because they’re equal and you were testing for that to make it positive 7, and this would be wrong but you aren’t marked down for it.

I was surprised anybody thought about the case for two negatives and it got me. I was being dumb. I think this might catch somebody now and then too.

Edit: Also, the hardest part of this was figuring out how to get at the numbers in the string, which I don’t think was the intention. Compared to that, the rest was easy.

It was difficult to obtain a 100% score. Al tests succeeded, but validation rejected my last solution several times. I had to jiggle around with the code a couple of times, before getting a 100% score. Yet I don’t see any real difference between my original and my final code.

Hy everybody,

I just want ask a question.

I success these puzzle 100% in python3 code, but when I send it for final validation, codingame give me only 90% because it’s wrong for the case where the temperature is empty.

But with the case 6, during the direct test, my code work when the temperature is empty and I print 0 correctly! I do a test on the temperature to know if it’s empty.

need your help!!
thank’s lot

1 Like

I am having the same trouble in Ruby.
Any suggestions appreciated, thanks!