Created
August 8, 2010 16:55
-
-
Save rick/514255 to your computer and use it in GitHub Desktop.
This file contains 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 pick(n, x) | |
raise "impossible" if x > n | |
return [n] if x == 1 | |
return [1] * x if x == n | |
choice = rand(n-x+1) | |
[ choice + 1 ] + pick(n - choice - 1, x - 1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment