get the temps into an array.
while there is no temps == 0 i do this :
- get all positive numbers into an array and the others (negatif) into another array.
- get the smalest of each array (positif and negatif)
- compare them and return the samlest.
There seems to be an error in the “All Negative Numbers.”
When I execute the code the output is:
Failure
Found: “2”
Expected: “-”
I am working in Swift
It appears that it is responding that “no number” is closest to zero, which is impossible. As I understand the instructions, if the absolute value of two numbers match, then the positive integer is considered closest. So a negative number set would still have a closest number. It appears that the expectation is that negative numbers are not being considered.
Am I doing something wrong?
Thanks for your help
Thank you very much for the response.
My question is, if the set is “-5 -3 -6”
The correct answer would be “2”
The puzzle is expecting “-”, which to me seems to be a non answer because you are to return the sequence number of the value closest to zero.
hey can anyone help? I have this so far:
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
temps = input() # the n temperatures expressed as integers in a a strind ranging from -273 to 5526
arry = temps.split(",") #every time a ',' is found in the input, that creates a new element.
arry2 = map(int, arry) # create a map that calls func 'int' to each item in arry
s = set(arry2)#make a new set out of arry2
try:
#print(s)
print(min(s, key=lambda x: abs(x)))#find the minimum of the abs vals of each item x in s
# Write an action using print
# To debug: print("Debug messages...", file=sys.stderr)
print("result")
except ValueError: #if the set has no vals, print 0
print(0)
but when I run, it would print an actual set(which is why it's commented out. can someone run it, and see if they can fix it?
every time i try to use the int() function i get the error “invalid literal for int() with base 10: ‘1 -2 -8 4 5’”
Like in this case:
temps = int(raw_input())
But I’d rather you explain the “bug” here first. It’s very rare to see bugs in classic puzzles (they’ve been solved by many other codingamers and not touched since a while.