Last active
August 29, 2015 14:07
-
-
Save epitron/529c15e8309cf5ec6da8 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
def some_combination_of_the_numbers_adds_to_the_biggest_number(arr) | |
arr = arr.sort | |
biggest = arr.pop | |
(2..arr.size).each do |perm_size| | |
arr.permutation(perm_size).each do |nums| | |
sum = nums.reduce(:+) | |
return true if sum == biggest | |
end | |
end | |
false | |
end | |
p some_combination_of_the_numbers_adds_to_the_biggest_number([1,2,3,4,8]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment