Hello ! ![]()
Iāve got a bug with this puzzleā¦
Unit test 2 and 3 :
Testing with one value = max range.
Testing with one value = min range.
Are not displayed in the run test part during coding, but there are displayed after submission..
So, I canāt reach 100% validation⦠![]()
Any answer ? ![]()
I donāt quite understand your question, but yes, you do have to write a solution general enough to pass the hidden validators. This applies to all puzzles here, where most of the visible cases are different from the validators.
SECOND EDIT
@5DN1L sent me a link to an article that answered my confusion, so thanks! Itās because of the split function. The array of numbers is being created at the top with
var inputs = readline().split(' ');
Here is the article they sent me to explain the split function, for anyone else as confused as I was.
Split Function Explained
END SECOND EDIT
EDIT
I still donāt understand why my original code didnāt work, but I updated it so that the following code is at the bottom, and it passed all test cases this way.
if (!arr[0]) {
return 0;
}
!arr[0] is the same thing as arr.length === 0 is it not!? So irritating, lol.
END EDIT
I do not understand why my code did not pass the final test case (an empty array). The first thing my code checks for is an empty array, and returns 0 if itās the case. That is what the last test case is looking for, but it kept telling me āSaw ānothingā expected ā0āā.
The first block of code in my tempClosestToZero function is:
if (arr.length === 0) {
return 0;
}
I passed all of the other test cases, but failed the last one, and it is driving me crazy. Am I just overlooking some stupid detail, or is this a bug?
I code with JS by the way.
Did you just return 0 without console.log(0)?
No, I made a function that returns either 0 or the closest to zero, and then console logged a call to that function. The function was returning the answer for all of the other cases and those were passing, so returning 0 shouldnāt have failed.
If you want, you can send me your code in private message and Iāll take a look.
Edit: The issue has been found: JavaScript splitting an empty string does not result in an empty array of length 0.
Hi! I am very young on the learning of Python 3 and i am struggling with this code.
How do you compare the value of a list? How can you find the minimal and maximum number of temperature? With which fonction. My code looks like this for now
tempnulle = 0
tempP = t
n = int(input()) # the number of temperatures to analyse
for i in input().split():
# t: a temperature expressed as an integer ranging from -273 to 5526
t = int(i)
if tempP > tempnulle :
result = tempP
tempP = max(t)
if tempP < tempnulle :
result = tempP
tempP = min(t)
if tempP == tempnulle :
result = 0
Thanks per advance,
KƩvin
It helps by forgetting code for a moment, and assume you receive the temperatures on some pieces of paper instead. In that case, how would you find out the answer, manually? After you find a working approach, you can then convert that into code.
Thx for you answer 5D.
I have modified the code but the answer i got is always the last number.
Where can be the issue?
Code :
tempnulle = 0
n = int(input()) # the number of temperatures to analyse
for i in input().split():
# t: a temperature expressed as an integer ranging from -273 to 5526
t = int(i)
tempPOS = t
tempNEG = t
temp_finale = t
if t > tempnulle :
tempPOS = t
if t < tempPOS :
tempPOS = t
# find positive value close to 0
if t < tempnulle :
tempNEG = t
if t > tempNEG :
tempNEG = t
# find negative value close to 0
if t == tempnulle :
tempnulle = 0
# If no temperature
ecartPOS = abs(tempPOS - tempnulle)
ecartNEG = abs(tempNEG - tempnulle)
if ecartPOS > ecartNEG :
temp_finale = ecartPOS
if ecartPOS < ecartNEG :
temp_finale = ecartNEG
# find and pick the closest number to 0
print(temp_finale)
Thx for your help
I tried to reformat your code as you pasted your code without indentation. Please edit it if itās still wrong (in particular the last part). Please remember to use the </> button on the formatting toolbar to format your code properly.
I cannot comment on your code until I see the properly indented code.
Also, can you describe in words (not in code) what your current approach is?
[Mod edit: Please avoid posting codes on the forum.]
litterally parseInt on the inputs held me hostage. i now know the importanceā¦that and ==vs===
Mabey is my mistake to understand the title enclearly, is there any one can help me check what is wrong with the programme like this:
while True:
def closest_to_zero():
try:
num1 = float(input())
num2 = float(input())
if abs(num1) < abs(num2):
return num1
elif abs(num1) > abs(num2):
return num2
else:
return max(num1, num2)
except ValueError:
print("Error!")
return None
result = closest_to_zero()
if result is not None:
print(f"The data more close to 0 : {result}")
choice = input()
if choice.lower() != 0 :
break
You arenāt reading the inputs properly, nor are you printing the answer in the required format.
Please follow the initial default code, and go from there.
I coded this in C#, and I was able to pass all test cases, but when I submit for credit, it fails me on #2 and #7 giving me only 82%. The hint says āThe following validators differ from the puzzle test cases to prevent hard coded solutions. This is why you can have some fails here even if all of the tests provided in the IDE have been successfully passed.ā However, nothing is hard coded, all variables to work with any data sent, which is what I thought all the test cases were to testā¦so I have no idea how to fix it.
The message is just a reminder that a hardcoded solution will likely fail; the most important and more relevant part of the message is the first part, i.e. tests and validators are different. That is why your code can pass all the tests and still may fail one or more validators.
The case names alone should be sufficient for you to guess what the validators look like:
Validator 2 is named ā-273 aloneā. That should be self-explanatory.
Validator 7 is named āTwo negative temperatures that are equal: {-10 -10}ā. That should also be self-explanatory.
Try making custom cases accordingly; you should then have an idea of how to fix your code.
Greetings, Using Lua here for Temperatures. I am stuck on the issue for 1, 2, & 5. While the code that i have inputted worked for 3, 4 and 6. It seems strange that it didnāt work for the first 2. Is there any ideas of what went wrong?
It sounds like youāre referring to the visible test cases (the ones shown before submission, not the hidden validators). You can view the specific inputs and expected outputs for each case by clicking the ābullet listā icon next to the āTest casesā section header. Once you have those, try walking through your code step by step using the inputs from the failing cases. This often helps reveal where things are going wrong.
If youāre still stuck after doing so, feel free to describe your approach here (without posting the actual code). Let us know what your code does for each failing test case: does it produce an incorrect result (and if so, what is it), or does it throw an error (and what is the error message)? That information will help others assist you more effectively.
Iāve used math.abs at first and using the if statements between t and zero (a local variable that Iāve made.) Itās also the first time that I used or. Even with Math.abs it used the wrong number. For example. Test case 1 is expecting a 1, but math.abs made it a 4, (5 without connecting the t to i). Without the t = i. Other test cases would fail. Another example is test case 2 where itās expecting a negative number. Instead itās a positive number (such as 2). The same could said for test case 5 where it needed a 2. But 9 was produced.
The main question here is why?
Itās impossible for math.abs to give you a wrong answer. You should check whether youāve passed the correct variable to the function, and if so, whether youāve updated the variable with the correct value beforehand.
As I mentioned earlier, try walking through your code step by step using the inputs. You may do it manually, or you may add debug statements to your code to print in the console the intermediate values of all the declared variables at the end of each iteration of a for-loop, e.g.
io.stderr:write("t = " .. t .. ", zero = " .. zero .. "\n")
If you need further help, please provide a full walkthrough for one of the cases you failed.