Skip to content

Instantly share code, notes, and snippets.

@miry
Created January 21, 2014 22:42
Show Gist options
  • Save miry/8549982 to your computer and use it in GitHub Desktop.
Save miry/8549982 to your computer and use it in GitHub Desktop.
# Codingame: http://www.codingame.com/ide/?target=clogin&s=1&id=227787048586488d4709f87be22b41eab2321d#!test:247723:true:%2523!list
n = STDIN.gets.to_i
if n == 0
puts 0
exit
end
values = STDIN.gets.split(' ').map(&:to_i)
closest = values.shift
closest_distance = closest.abs
values.each do |value|
distance = value.abs
next if distance > closest_distance
if distance < closest_distance || value > closest
closest = value
closest_distance = closest.abs
end
end
puts closest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment