Ruby calorie calculation output

This is my own output.

I did a program to calculate the calories of the food I ate.

M = number of food items N = number of people food = calories per gram eat = how many g you ate carolie = total calories

qiita.rb


M,N = gets.chomp.split(" ").map{|i| i.to_i}

food = []
i = 0
M.times do 
  i = (gets.to_f / 100)
  food.push(i)
end


eat = []

N.times do
  i = gets.chomp.split(" ").map{|i| i.to_i}
  eat.push(i)
end

i = 0
f = 0
total = []
count = N
count1 = M - 1
calorie = 0

while count > 0 do
  for s in 0..count1 do
    calorie += (food[i] * eat[f][s]).floor
    i = i + 1
  end
  total.push(calorie)
  calorie = 0
  i = 0
  f = f + 1
  count = count - 1
end


puts total

I'm not so used to using for sentences, so I'm glad I could use it this time. Perhaps I felt that I could condense more by using a two-dimensional array this time, but it didn't work. .. ..

Recommended Posts

Ruby calorie calculation output
[ruby] drill output
[ruby] drill output
[ruby] drill output
Ruby standard output
[ruby] drill output
[ruby] drill output
[ruby] drill output
[ruby] drill output
Ruby score calculation program
Output triangle in Ruby
Birthday attack calculation in Ruby
[Ruby on Rails] CSV output function
String output method memo in Ruby
Ruby / Rust linkage (3) Numerical calculation with FFI
Ruby print puts p printf output method
Ruby / Rust linkage (4) Numerical calculation with Rutie
From terminal to Ruby (standard input / output)