Skip to content

Instantly share code, notes, and snippets.

@vinbarnes
Forked from rick/gist:514255
Created August 9, 2010 03:06
Show Gist options
  • Save vinbarnes/514865 to your computer and use it in GitHub Desktop.
Save vinbarnes/514865 to your computer and use it in GitHub Desktop.
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