Hacker Rank Solutions: Filling Jars

Hacker Rank Solutions: Filling Jars

1
2
3
4
5
6
7
8
9
10
jars, moves = $stdin.gets.chomp.split(' ').collect { |x| x.to_i}
total = 0
moves.times do |x|
  jar1, jar2, ammount = $stdin.gets.chomp.split(' ').collect { |x| x.to_i }
  no_of_jars = (jar2 - jar1) + 1

  total = total + ( no_of_jars * ammount )
end

puts (total / jars).floor

Comments