gets as = gets.split.map &:to_i d_min = Float::INFINITY as.each_cons(2) do |a, b| diff = b - a d_min = (diff < d_min) ? diff : d_min end d_max = as[-1] - as[0] p d_min p d_max