Skip to content

Instantly share code, notes, and snippets.

@epitron
Last active August 29, 2015 14:07
Show Gist options
  • Save epitron/529c15e8309cf5ec6da8 to your computer and use it in GitHub Desktop.
Save epitron/529c15e8309cf5ec6da8 to your computer and use it in GitHub Desktop.
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