Skip to content

Instantly share code, notes, and snippets.

@hindenbug
Created June 11, 2014 18:09
Show Gist options
  • Select an option

  • Save hindenbug/eed09788e7efea62a8b9 to your computer and use it in GitHub Desktop.

Select an option

Save hindenbug/eed09788e7efea62a8b9 to your computer and use it in GitHub Desktop.
TapeEquilibrium
def solution(a)
# write your code in Ruby 1.9.3
rsum = a.inject(:+)
lsum = 0
res = nil
a.each_with_index do |v, i|
rsum -= v
lsum += v
diff = (lsum - rsum).abs
res = diff if res.nil? || diff < res
end
return res
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment