Created
May 17, 2012 15:10
-
-
Save dmitryn/2719547 to your computer and use it in GitHub Desktop.
Array#complect
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
| 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