-
-
Save Teino1978-Corp/b6e1a67311f4b22b9238 to your computer and use it in GitHub Desktop.
Pivot Algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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