Skip to content

Instantly share code, notes, and snippets.

@dmitryn
Created May 17, 2012 15:10
Show Gist options
  • Select an option

  • Save dmitryn/2719547 to your computer and use it in GitHub Desktop.

Select an option

Save dmitryn/2719547 to your computer and use it in GitHub Desktop.
Array#complect
class Array
def complect(n)
ret = []
n.times { ret << 1 }
while ret.sum < self.sum
ret[rand(ret.size)] += 1
end
ret
end
def sum
self.reduce(&:+)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment