RosettaCodeData/Task/Equilibrium-index/Ruby/equilibrium-index-3.rb

13 lines
224 B
Ruby
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
def eq_indices(list)
left, right = 0, list.sum
equilibrium_indices = []
list.each_with_index do |val, i|
right -= val
equilibrium_indices << i if right == left
left += val
end
equilibrium_indices
end