Skip to content

Instantly share code, notes, and snippets.

@gary-rafferty
Created May 10, 2013 19:10
Show Gist options
  • Save gary-rafferty/5556677 to your computer and use it in GitHub Desktop.
Save gary-rafferty/5556677 to your computer and use it in GitHub Desktop.
zerosum
def zerosum(arr,size=4)
arr.permutation(size).to_a.each do |a|
if a.inject(:+) == 0
p a.inspect
break
end
end
end
zerosum([2,3,5,6,7,8,9,1,2,3,-1,-11,44,-1,0,1,1],5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment