Created
October 30, 2014 05:53
-
-
Save jin/1d0157eb8d825b7493ab to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
def sum_of_differences(arr) | |
total = 0 | |
arr.each_cons(2) do |x, y| | |
total += (x - y).abs | |
end | |
total | |
end | |
puts sum_of_differences [143, 86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130] | |
puts sum_of_differences [143, 130, 86, 913, 948, 1022, 1470, 1509, 1750, 1774] | |
puts sum_of_differences [143, 913, 948, 1022, 1470, 1509, 1750, 1774, 130, 86] | |
puts sum_of_differences [143, 913, 948, 1022, 1470, 1509, 1750, 1774, 86, 130] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment