[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

qiita.rb


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
end
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"
  else
    puts "no"
  end
  n = n-1
  c = c + 1
end

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

qiita.rb


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.

Tags:

Updated: