I think you forgot to read the temperatures from standard in.
Question:
-Iâm using VB.net
-what how is the data âtempsâ and how can I convert it into an integer array?
Split the string by â '(space), then parse the elements of the array to use them as Integer
Hi,
Tell me please.
I used array.Split(â '); to record values from a string to an array. Then used Array.ConvertAll to convert string array to int array.
Now I have array that records the data from the variable temps.
( string temps = Console.ReadLine(); // the n temperatures expressed as integers ranging from -273 to 5526)
How can I identify the nearest number to 0 considering the conditions of the game.
Maybe there is some kind of function?
I do not understand how to compare the same number of positive and negative values.
Thank you!
Thatâs your task. You have to write that function.
Bonjour,
Je code en C et jâai un souci.
Est ce que le programme doit renvoyer la température ou son indice dans le tableau ?
Car dans la description du puzzle on parle de tempĂ©rature, par contre pour rĂ©ussir les tests cases il faut renvoyer lâindice de la tempĂ©rature dans le tableau.
Est ce normal ?
Itâs the temp.
I modified the stub code to this:
var n = parseInt(readline()); // the number of temperatures to analyse
var temps = readline().split(' '); // the n temperatures expressed as integers ranging from -273 to 5526
Now when I try to run through this array as
var closest = temps[0];
for (i = 0; i < n; i++){
if ((temps[i] > closest)&&(temps[i] < 0)){
closest = temps[i];
printErr("It's closer!");
}
}
The check fails for the values [-5, -4] in test 2. Why is this seeing -4 as being lesser than -5?
You works with string. so -4 < -5
My first and second IDE tests (in C) appear to be broken.
For the first: Iâm having it print all the values in the array before doing it. Iâm getting:
49
32
45
0
-1
Result: -1
But it says
Expected: "1"
For the second: Iâm getting:
45
5527
53
32
45
45
52
32
45
50
0
8
32
Result: 8
But it says
Expected: "2"
Neither of these make sense.
Pretty sure this puzzle while using python has a few bugs and itâs rather annoying.
Bug 1:
As written in the âGame Rulesâ -
âLine 2: The N temperatures expressed as integers ranging from -273 to 5526â
This is inaccurate, the N temperatures are expressed as a string, not as integers. you have to split the string into an integer list.
Bug 2:
The Validator returns the following as False:
âIt works when inputs contains only negative numbers: : {-15 -7 -9 -14 -12} -> -7â
Last time I checked, -7 is the correct value⊠wtf? and this is made even more confusing when the second to last validation passesâŠ
âIt works with two negative temperatures that are equal: {-10 -10} -> -10â
Bug 3:
I also fail test 2 and 3 but have no idea why⊠I have a statement in my code that says
templist = map(int, temps.split(' '))
templist.sort()
cval = min(templist, key=abs)
if n == 1:
cval = templist[0]
Which is I would think is pretty freaking standard, if there is only 1 value in the list⊠just pass that value⊠it works on my IDE⊠why not the validator?
Iâm having almost the exact same issue in Python.
I can pass all three tests, but the validators fail on the following two:
It works when inputs contains only negative numbers: : {-15 -7 -9 -14 -12} -> -7 250
When two temperatures are as close to 0, then the positive wins: {15 -7 9 14 7 12} -> 7 750
Why would the only negative numbers test fail and the two same negative numbers test pass? Isnât that basically the same thing?
Hello CodinGamers,
Temperatures was one of our first puzzles and there is not enough tests in IDE, plus validator names are not helping to understand what is going on.
As an example: â{-15 -7 -9 -14 -12} -> -7â is the name of a test. I mean that â-> -7â is not meaning your output is -7 on this test case.
We will work on this puzzle next week.
Ide test cases updated and validators renamed.
These modifications should avoid issues.
You beautiful bastard. Thanks for the help!
If anyone else is having problem whit the -10 -10 test, it seems the result must be positive even if both temperatures are negative.
I can assure you that in that case, the result is negative.
Bonjour,
Jâai un petit souci avec le tableau de tempĂ©ratures: câest un tableau de caractĂšres, alors, comme ce nâest pas bien pratique en C, je le transforme en tableau de nombres (int) avant de faire les test.
Pour cela, je parcours le tableau en faisant une petite boucle while(temps[i]!=â\0â), vu quâun tableau de caractĂšre est censĂ© toujours se terminer par â\0â
Seulement voilĂ , aprĂšs avoir passĂ© les diffĂ©rents tests, je mâaperçois que cette boucle fait un âtourâ de trop. Comme sâil y avait quelque chose entre le dernier caractĂšre (un chiffre, donc) et la fin du tableau. Quelque chose qui nâest pas un espace et qui me renvoie un nombre qui nâa rien Ă voir avec ce que jâattendsâŠ
Pour palier Ă ce problĂšme, jâai trichĂ©: jâai transformĂ© ma boucle en while(temps[i+1]!=â\0â)
Je mâarrĂȘte donc quand le caractĂšre SUIVANT est la fin du tableau, et je ne traite pas le dernier caractĂšre avant la fin.
Cette mĂ©thode marche trĂšs bien⊠sauf pour le test n°2. Dans ce test, le tableau semble mieux dĂ©fini (câest Ă dire quâil sâarrĂȘte bien juste aprĂšs le dernier caractĂšre) et du coup, comme ma nouvelle boucle sâarrĂȘte avant, je âzappeâ le dernier chiffre (1337 devient 133âŠ)
Jâaimerais donc savoir comment ces tableaux de char sont dĂ©finis exactements, pourquoi il y a âquelque choseâ entre le dernier caractĂšre et la fin, et pourquoi ce quelque chose nâest pas dans le test 2.
Ă noter que cela nâempĂȘche pas la rĂ©ussite de tous les tests, puisque la derniĂšre valeur nâest jamais la plus proche de 0.
Merci
can someone please help me?
i have my code set up to where i have to manually change the code each test, and it will pass all but the last one, where there are no inputs.
hereâs my code so farâŠ
// function for finding closest number to 0
function closest(num, arr) {
var curr = arr[0];
var diff = Math.abs (num - curr);
for(var val = 0; val < arr.length; val++){
var newdiff = Math.abs (num - arr[val]);
if(newdiff < diff){
diff = newdiff;
curr = arr[val];
}
}
return curr;
}
// test cases in one array
var i = 0;
array = [
simpTest = [1, -2, -8, 4, 5],
onlyNeg = [-12, -5, -1337],
chooseRtemp = [42, -5 * -1, 12, 21, 5, 24],
chooseRtemp2 = [42, 5, 12, 21, -5 * -1, 24],
complex = [-5, -4, -2 * -1, 12, -40, 4, 2, 18, 11, 5],
noTemp = []
];
n = array.length[i]
number = 0
print(closest(number, array[0]));
is there a way to have the code do each array by itself, for all the test cases??
Perdonad pero me da un error que dice que tengo mi codigo como Hard Coded aun pasando las pruebas.
Aqui esta mi codigo
[EDIT: NO FULL CODE]
Alguien me puede decir cual es el problema?