Temperatures puzzle discussion

Well, TEMPS is actually given as a whole string if I’m not mistaken. I solved this problem by using “split()”.

var tempArray = TEMPS.split(" ");

That gave me an array with each number (despite it being positive or negative) as one of the values in the array. And then I just had to access them with tempArray[N].

It worked well for me. :wink:

1 Like

So I just put my code into JSFiddle, and there was a bug in my code. I read the results wrong, I thought it was showing what I returned not what was expected. Hopefully this helps.

Dear Codingame,

I made a solution in C++, after the first build I passed on all tests, but then i realised a logical mistake in my code, and fixed it. Then my code fails on your complex test, but in my opinion, it should not.

Input data:
10
-5 -4 -2 12 -40 4 2 18 11 5

-2 is my result, which is just as right as 2. Please fix your control mechanism, or change the test samples!
Thank you!

OUTPUT:

  • Display 0 (zero) if no temperature is provided
  • Otherwise, display the temperature closest to 0, knowing that if two numbers are equally close to zero, positive integer has to be considered closest to zero (for instance, if the temperatures are -5 to 5, then display 5)

Sorry, my mistake.

I can not understand why my code is not getting all points.All 3 cases pass,btw I know that the IDE tests are different.I do not know what to do…I did not use any char/string or such.Used c++ sort then some if condinionals…

No full code, read topic, explain what you did

Your code output 0 instead of 1 for [7 5 9 1 4]

Can you describe your algorithm?

Drop from a to b can only happen if a appears before b in time.

template of solution in Go for this puzzle is somewhat misleading
i solved it but i would have spent much less time with correct template
please check one more time

Hi,

Not sure what I’m doing wrong.

I loop over the items
I have the absolute value of the current item
I also have the absolute value of the previously lowest item
If the absolute value of current item is less than or equal to previous absolute value, then I do a check
If the value is greater than previous value (i.e. 5 beats -5), then I set the lowest item to current value
Otherwise I ignore it.

I pass all of the IDE tests yet fail the following

  • Result is correct with a simple data set: {7 5 9 1 4} -> 1
  • When two temperatures are as close to 0, then the positive wins: {15 -7 9 14 7 12} -> 7
  • When two temperatures are as close to 0, then the positive wins 2: {15 7 9 14 -7 12} -> 7

Any suggestions?

There is one thing I find weird.

So if you had 2 as best value and you tried -1:
Absolute value of -1 is 1, it is less or equal to 2 (the previous absolute value). However -1 is not greater than 2, so you ignore -1.

Still -1 is closer to 0 than 2 and you ought to keep it.

Perfect. Thanks :smile:

The image in combination with the description speaks more or less for itself, but i think it would be more consistent if the title of the axis are in english :wink:

edit: The input-file for the last test displays a “0” for me, but in practice, the input is an empty string “”

Which language you are doing it in ? Just finished it in C++ and it was just fine.

When using C code, the input is set as an array of chars while the values varies between -273 and 5526 which a char can’t handle (-127…127), at least signed short should be used to handle the extreme values.

nevermind, my bad, i didn’t understand well the purpose that you have to parse a text string and not use the content of TEMPS directly

A few things should be made clearer in the description:

  • “display the temperature closest to 0” should say “print the temperature that is closest to 0”. Okay, not much improvement there, but I mistook it to mean a reference (the index) to the temperature.
  • It should be made clear that there are only unique values in the TEMPS array.

And for the stub code:

  • The TEMPS variable should parse the string into an array or something. That’s what I assumed it to be, and even passed the first test with that assumption!
1 Like

hello, i’m having some trouble with inputs at VB.net, isn’t this the correct way to declare a array?
this code returns a error in console “error VBNC30471: Only arrays and methods can have argument lists” in second line

Dim xpto as integer(8)
xpto(1) = 2

help for the newbie much appreciated :slight_smile:

The correct is:
Dim xpto(8) as integer