Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def index(list=[])
- sum_left = 0
- sum_right = list.inject(0,:+)
- list.each_with_index do |value, index|
- sum_right -= value
- return index if sum_right == sum_left
- sum_left += value
- end
- -1
- end
- list = [1,2,3,4,3,2,1]
- print index(list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement