Temperatures puzzle discussion

my code broke on just the first case. I tried changing it around but I was never able to get as far. I need the temp to compare numbers so it’s not just checking if t is less then inputs[t+1].
my nested if statement checks if temp is greater than t. if so then it will turn it into t.
if (curretNum is less than nextNum)
check if (assumedAnswer is greater than currentNum)
if true change assumedAnswer to currentNum
on the simple test I had the problem that it was checking if t is less than the inputs[t+1] then changing it to t so in 1 -2 -8 4 5 it would out put -2 or 4 because the absolute value of 1 is less than 2 but not 8 and 4 is in fact less than 5

i’ll continue seeing if I can make temp better. or fix up my logic but so far I can’t get rid of it due to it being my best solution

I can solve this puzzle with simple min and max. here is my code

Admin Edit: please refrain from posting full working code. Prefer to publish your solution and link to it.

im have a lot of trouble trying to figure out how to even start doing anything and im using ruby to code and i have now clue where to start

I solved this in Clojure, but unfortunately the boilerplate code provided for reading stdin for the test cases results in a NumberFormatException because the call to Java’s Integer/parseInt cannot handle the empty string for test case 6.

Any thoughts?

(defn -main [& args]
   (let [n (Integer/parseInt (read-line))
     t (map #(if (= % "")
               0
               (Integer/parseInt %)) (set (str/split (read-line) #" ")))]
 (output (.......))))

I used this to capture the empty string instead of allowing the parseInt method to throw an exception when fed invalid input.

1 Like

thank you for reporting this issue. We’ll look into it

enfin j’ai réussi à résoudre le puzzle c’était facile mais j’etait pieger avec scanf de la valeur de n après la condition
finally I managed to solve the puzzle it was easy but I was trapped with scanf of the value of n after the condition

Привет. Не могу понять почему не проходит 6 тест.

Мой код

const n = parseInt(readline());

var inputs = readline().split(' ');

const listNegative = [];

const listPositive = [];

let zeroT = null;

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

    const t = parseInt(inputs[i]);

    if (t > 0) {

        listPositive.push(t)

    } else if (t === null) {

        zeroT = 1;

    } else {

        listNegative.push(t)

    }

}

const maxNegativT = Math.max(...listNegative);

const minPositiveT = Math.min(...listPositive);

if (zeroT === 1) {

    console.log(0);

} else if (listNegative.length === 0) {

    console.log(minPositiveT)

} else if (listPositive.length === 0) {

    console.log(maxNegativT)

} else if (minPositiveT * (-1) <= minPositiveT) {

    console.log(minPositiveT)

} else {

    console.log(maxNegativT)
}

Your code never reaches the line
if (t === null)
when there are no temperatures.

1 Like

y = n

for e in range(n):

if n < y:

    if n < 0:

        if n + y == 0:

            y = y

        else:

            y = n

print(y)

je ne vois pas le problème sa me marque au niveau 1 que n = 5

for those who where asking for answer…
‘’’
[nope]
‘’’

You are not supposed to post your solution code here :open_mouth:

Here’s the python3 answer for anyone who still needs it:

[nope]

The cases which supposed to eliminate hard coded solutions forced me to hard code a solution…

Hello, i have an issue with this challenge. I’ve written my code with python but every time I’m running the test cases they all failed but when I tried on my IDE(Pycharm), I got the right answers of the test cases. Dunno how you could help me. Thank you!

Some of the possible reasons are that your code times out (because Codingame specifies a time limit for your code to produce the answers), or your code does not output the answer in the required format here.

What errors does the console show here when your code fails?

Hello i’m a newbie, i compiled my code with g++ on linux mint and the test case with single value -273 and 5526 works fine on my IDE at home.
I am flummoxed however that when I submit my code to the Codingame platform, there is an error message for those 2 particular cases.
I will send my code to the IDE since I would really like to understand why there is a difference in the results. Thanks for any advice or help you can proffer.
Leish

What error message you saw?

Hey I hope you are well. So I attempted the question and got it right but wanted to try a different method. Please see below. It did not test correctly, is there any tips on how to fix it?

class Program
    {
        static void Main(string[] args)
        {
            int[] inputs = new int[] { -230, -20, -10, -100, 20000, 100, 5, 95, 32, -30 };
            int closest = inputs[0];

            for (int i = 1; i < inputs.Length; i++) {
                int t = inputs[i];
                if (Math.Abs(closest) > Math.Abs(t))
                    closest = t;
            }

            Console.WriteLine(closest);
        }
    }

Your code gives the correct answer 5. However, your code may fail in the cases where

  1. there are no inputs, or
  2. the inputs contains two numbers which have the same absolute amount and one number is positive while the other number is negative.
2 Likes

Hello, I did the test in php on my IDE and everything is fine. Except on the IDE of codingame the identical positive and negative temperatures are not validated.
An idea? here is my piece of code.

indent preformatted text by 4 spaces`if (!$n){

echo(0);
die();
}

$numPos = array_filter($inputs, function($var){return ($var > 0);});
$minPos = $numPos ? min($numPos) : null;

$numNeg = array_filter($inputs, function($var){return ($var < 0);});
$maxNeg = $numNeg ? max($numNeg) : null;

if ($minPos && $minPos <= abs($maxNeg)){
echo($minPos);
} else if (!$maxNeg){
echo($minPos);
} else {
echo($maxNeg);
}`