Temperatures puzzle discussion

When you see an error about “Nothing”, it means you are either missing a carriage return or have too many of it in your answer.

Thanks for the info, I didn’t know what a carriage return was so I googled and found that this is \r and it’s like \n. By the way my code is in C++. I don’t use any of those in my code so that would mean that I am missing a \n or \r. How is that even possible ? That would mean that return carriages are mandatory sometimes ? Sorry for my confusion but as you guessed I’m pretty new to coding :-/
If anyone has another clue for me, it would be really appreciated, thanks :wink:

There are many ways to output a CR. Most puzzles here expect one CR (not more, not less) after an output line.

In C++ you can output the answer (if your answer is in variable n) like this:
cout << n << endl;

Btw, C++ also accepts C codes. You can do it in C style:
printf("%d\n", n);

Same here, i display “1” but
Failure
Found: a…
Expected: 1

And there is nothing that could print an a in your code? I sometimes forgot the auto generated print statement somewhere down in my code

The reason why my code printed 0 instead of 1 was that I sorted an array which had a higher size than it had numbers in it, so the empty spaces just turned into 0 and that was the first value in the array. That still wouldn’t start with a, though…

Bonjour,

Voila, j’ai 90% de réussite, le test 5526 alone ne passe pas.

Le truc, c’est que le -273 alone fonctionne bien, je ne vois pas d’erreur dans mon code, et quand je rentre en dur 5526 pour le input, le résultat affiché est bien 5526.

J’aurai raté quelque chose ? ^^

//

Hi,
I don’t understand why i didn’t get 100%.
5526 alone test failed.
But all other are good even -273 alone

When i put myself 5526, the result is correct, but not with the test.

Did I miss something ? ^^

1 Like

I don’t know why it works while hardcoding 5526 in input, but during the validator, your code outputs: -5526 :slight_smile:

Oh ! ^^

Maybe i read too fast and miss the “-” xD
I’ll look at it.

Either way, Thanks a lot, that should help =)

EDIT : Done ! ^^
I didn’t handle the one number case xD
Work better now =)

Thanks !

My result is coming up as wrong for the “choose the right temperature” and “complex test case” because I’m returning a negative when it’s expecting a positive, the directions say, “If two numbers are equally close to zero, positive integer has to be considered closest to zero (for instance, if the temperatures are -5 and 5, then display 5).” I assume if they are both negative then we should the negative. I’m confused by the directions perhaps, but it seems to me that if you have two -5 then you should return a -5 since there is no positive 5. Can anyone shed some light on this?
If I am supposed to return a positive when I have two negative numbers then the directions are pretty unclear, but can someone help guide me towards how I should approach this? I’m using Python3.
Thanks.

There are no test cases where there are 2 values of -5. If your code is finding 2 values of -5, then there’s something wrong with the code you have that reads the values.

However, if there were a case where there were 2 values of -5 and no other values were closer to 0, -5 would be the correct answer.

You can look at the test cases if you select Expert Mode from the options and then click on the square in the test cases panel.

1 Like

Hello,

The OCaml code skeleton is bugged, you give: the following code:

let n = int_of_string (input_line stdin) in (* the number of temperatures to analyse *)
(*let line = input_line stdin in*)

for i = 0 to n - 1 do
    (* t: a temperature expressed as an integer ranging from -273 to 5526 *)
    let t = Scanf.sscanf line "%d" (fun t -> (t)) in
    ...
done;

but working over a string sscanf will not “eat” the current char and iterate n time over the same int.

One solution is the following:

  1. replace line by:

    let line = Scanf.Scanning.stdin in

  2. replace the sscanf by a bscanf:

    let t = Scanf.bscanf line "%d " (fun t -> (t)) in

Another solution in a functional way (OCaml programmers like functional structures, it is a big disappointing (and unusual) to be confronted to imperative for loops):

let _n = int_of_string (input_line stdin) in (* the number of temperatures to analyse *)
let line = input_line stdin in
(* t_lst: a list of temperatures expressed as an integer ranging from -273 to 5526 *)
let t_lst = (List.map int_of_string (String.split_on_char ' ' line)) 
in
(*your code here*)

This should be more expected for an OCaml programmer to code from a List than from a loop (but I can understand you want a very similar pattern for every language).

1 Like

I don’t have any hard-coded values but validation fails on test case 3. On IDE, everything checks out.

I am a beginner of programming, why I made the mistake here?(I even don’t know how to deal with the first case)
PLEASE HELP

fscanf(STDIN, "%d",
    $n // the number of temperatures to analyse
    );

$inputs = fgets(STDIN);
$inputs = explode(" ",$inputs);

$near = $inputs[0];


for ($i = 0; $i < $n; $i++)
{
    if ( abs($near) >= abs($inputs[$i+1]) ) {
        $near = abs($inputs[$i+1]);
        
    }
   
}  

 echo($near);

Well, yes. The $inputs array has indexes ranging from zero to ($n-1) and you iterate the variable $i in the ‘for’ cycle also from zero to ($n-1). So far so good :slight_smile: But the body of ‘for’ is referring to $inputs[$i+1]. This is problematic, because when $i will reach its last value of $n-1, then the $i+1 is equal to $n. Number $n is not one of the valid indexes for $inputs and your program throws an error. You could try to use simply $i instead of $i+1 in ‘for’ construct. This will get your program to run, but the program logic too has to be little bit adjusted to get the correct answers.

Has anybody understood the third test case? I didn’t understand what exactly “Choose the right temperature” means.

Just print the inputs!

Hi everybody,
I’m trying to do this in C++, but cant succeed convert the String in a list of integer ?
I tried atoi but seems, not working, isstreaml too… i dont see how to do, an advice about a class/function ?

Thks

I feel like my logic is solid but maybe I’m making a syntax error Can someone help me? I set the program up to separate the positive and negative numbers and now it keeps returning the positive numbers array as being null. I keep looking over the code and can’t see where I went wrong any suggestions. Also not sure if pasting code here is allowed so I’m not.


larryjoe use the int function (https://docs.python.org/3/library/functions.html#int).


I have same failure (5526 alone test) and i can’t understand why!

Input is not printing with System.out.prinltn(i); in the for loop please anybody knows give me reply