File.open("OUT1.txt", "w") do |f| IO.foreach("DATA1.txt") do |line| angle = (line[0] -48).to_s + (line[1] - 48).to_s velocity = (line[3] -48).to_s + (line[4] - 48).to_s + (line[5] - 48).to_s cos = (Math::cos(angle.to_i * (Math::PI / 180)) * 100) sin = (Math::sin(angle.to_i * (Math::PI / 180)) * 100) distance = ((sin / 9.81) * 2) * cos puts distance.round f.printf "%s\n", distance.round end end