Temperatures puzzle discussion

Please note that after you submit your code, your code is tested using validators, which are different from the visible test cases. That is why it is possible that your code passes all test cases but is not general enough to pass the validators too. In that case, you have to revise your code.

And about your code, I do not understand the logic of “check_if_result_is_0_or_1”. Your code will return 1 if the given numbers include both 0 and 1, but the answer in such a case should be 0.

When I google “Validators” I get a lot of explanations of what to do to validate that a user has entered in the correct information, but not much beyond that.

Anyways, I put that function in there because I figured if there was a 1 or a 0 in it because those numbers are obviously close to 0 or 0 itself. I swapped them around to fix this, however, I am realizing now that I probably should only be looking for just 0, as my later function call would sniff out the 1 to begin with. If I remove the 1 section of the code it fails on the first on and the third on of the submission. I would need to further revise, but I would like to solve this 5526 problem first.

def check_if_result_is_0_or_1(number):
    result = 0
    if 0 in number:
        result = False
        return result 
    elif 1 in number:
        result = True
        return result
    else:
        result = 4
    return result

However, if there is a number greater then 0, then it should return a 4 which I used to determine that there is no 1 or 0 and therefore to continue on. The result should come out 5526 and does when I run it through an external IDE.

A validator on CodinGame is just a hidden test case for testing your code on submission.

I belive if 0 in number: result = False return result
should not work here.

Temperatures puzzle discussion - #942 by CraigVarley check this out :slight_smile:

I have it +90% complete except -10 -10 case. I am not sure how you understand “Two negative temperatures that are equal: {-10 -10}”= -10 -10 or any 2 negatives values in the array ?
Anyhow i tried both and it doesn’t validate :frowning:

In case of ties, just choose any one because it does not change your answer. For example, if the input is “-10 -10”, then output -10 as the answer; if the input is “-5 -5 -10 -10”, then output -5 as the answer.

I am not sure what inputs that validator provide, but your code should be general enough to cover any cases. An easy approach would be:

  1. initialise an answer as a starting point, e.g. 10000
  2. read a temperature
  3. if the newly read temperature is better than the existing answer, replace it
  4. go back to step 2

Except for the special case of no temperatures being provided, the above approach can deal with any number of temperatures and it does not matter they are positive or negative, or they are ties or not.

#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

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

    cin >> n; cin.ignore();

    int min=5600;

    int index=-1;

    for (int i = 0; i < n; i++) {

        int t; // a temperature expressed as an integer ranging from -273 to 5526

        cin >> t; cin.ignore();

        if(abs(t)<abs(min))

        {

            min=t;

            index=i;

            //cout<<min<<endl;

        }

    }

    // Write an answer using cout. DON'T FORGET THE "<< endl"

    // To debug: cerr << "Debug messages..." << endl;

    //cout << "result" << endl;

    cout<<index <<endl;

    cout<<min<<endl;

}

here is my code in codeblocks. it works well while negative in codinggame. i am not sure what’s wrong.

Your code does not work for cases when a negative minimum appears before a positive minimum of the same magnitude, e.g. for the case of -5, 5, your code will output -5 instead of the expected answer of 5.

Also, your code will output both index and min to the standard stream. Anything extra in the standard output will be treated as wrong. As can be seen in the comments near the end of your code, you should use cerr instead, e.g.

cerr << index << endl; // for debugging
cout << min << endl; // for answering

btw you can format your code properly by using the </> button on the formatting toolbar in this forum :wink:

Hello, another question about this weird “no temperature”… I’m on Java, I tried

System.out.println("");
System.out.println("0");
System.out.println(0);
System.out.println(n);

and I NEVER passed this test !
I give 0 ? “nothing” await. I give “” ? “0” await.
Please, I want my 100%…

Maybe the issue is that your code never reaches that line of code?

@Lainea I think it should be System.out.println(0), not “0”. Now, what is your condition to print 0? In my case, I put all my temperatures in an int array. If the array has length ==0 then it means no temperatures were provided.

Hello, this is my condition :

        if (n == 0) {
            System.err.println("rentre ici");
            System.out.println(0);
        }

I enter into the if, my error message “rentre ici” is visible.

I also tried to do the job with an array, same problem. I enter into the if. I write 0 → nothing is expected. I write “” → “0” is expected. I write “0” → nothing is expected…
I passed all the others tests

        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = in.nextInt();
        }
        if (array.length == 0) {
            System.err.println("rentre ici");
            System.out.println(0);
        }

Your code snippets look fine, so there may be an issue somewhere else.
You may send me your full code in private message and I will take a look.

Thank you for your offer ! But I’m sorry, I don’t see how I can message you :
“Need to have a direct personal conversation with someone, outside the normal conversational flow? Message them by selecting their avatar and using the message button.”
From this page, I click on your avatar, I access to your user page… I never see this message button

I’ve sent you a PM just now (FYI, by clicking on Message button as shown in the screenshot below). You may continue by replying to me there.

Hello tous. Je débute en C, autant dire que je ne réussis aucun puzzle :rofl:. Du coup, ce qui m’intéresse c’est juste d’avoir des réponses pour apprendre. On peut les trouver quelque part ? J’ai cherché, mais je n’ai pas trouvé sur la page du jeu. Tx & bonne journée à tous

You don’t have access to the solutions on this website until you have solved the puzzle in the same programming language yourself.

Hello, je suis dans le même cas. Tu as trouvé une solution depuis ?

Merci.