-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoder_pad_tutorial.rb
More file actions
47 lines (41 loc) · 920 Bytes
/
Copy pathcoder_pad_tutorial.rb
File metadata and controls
47 lines (41 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# https://screen-ide.coderpad.io/23996223
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = 1 # gets.to_i
inputs = "-10 -10" # gets
def negative_check(number)
if number < 0
number -= 0.1
end
number
end
def closest_temp(n, inputs)
if inputs
puts "inputs: #{inputs}"
inputs = inputs.split
puts "inputs: #{inputs}"
else
puts "inputs falsy"
return 0
end
closest = inputs[0].to_i
puts "closest: #{closest}"
closest = negative_check(closest)
puts "closest: #{closest}"
index = 1
while index < n
puts "index: #{index}"
number = negative_check(inputs[index].to_i)
if number.abs < closest.abs
closest = number
end
index += 1
end
if closest < 0
closest += 0.1
closest = closest.to_i
end
return closest
end
# Write an answer using puts
puts closest_temp(n, inputs)