[Ruby] How can I efficiently fill the array?

less than 1 minute read

I will post it somehow. I was writing a program in ruby, but I realized that I still have a poor understanding of sequences. For example this


xc,yc,r_1,r_2 = gets.chomp.split('').map{|i| i.to_i}
n = gets.to_i
x = []
y = []
n.times do
  a,b = gets.chomp.split('').map{|i| i.to_i}
  x.push a
  y.push b
c = 0

while n >0 do
  if r_1**2 <= ((x[c]-xc)**2 + (y[c]-yc)**2) && (x[c]-xc)**2 + ((y[c ]-yc)**2) <= r_2**2
    puts "yes"
    puts "no"
  n = n-1
  c = c + 1

The content of the process (while) does not matter at this time

By that time, Define array of x and y define variables a and b Store a and b variables in an array in order

Is repeated. While I was writing, I thought that I was writing code like a stupid thing I can’t think of any better means.

Originally do not use a, b


x,y = gets.chomp.split('').map{|i| i.to_i}

I wish I could have stored this form from the beginning. I would also like to explore means.