Skip to content

Instantly share code, notes, and snippets.

@bridgpal
Created August 5, 2014 19:24
Show Gist options
  • Save bridgpal/f5403639f8c46a2320f1 to your computer and use it in GitHub Desktop.
Save bridgpal/f5403639f8c46a2320f1 to your computer and use it in GitHub Desktop.
Pivot Algorithm
input = [1, 4, 6, 3, 2]
def get_pivot(input=[])
1.upto(input.length-2) do |pivot|
left = input[0...pivot].inject(:+)
right = input[pivot+1..-1].inject(:+)
return pivot if left == right
end
return -1
end
puts get_pivot()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment