Skip to content

Instantly share code, notes, and snippets.

@raorao
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raorao/9594552 to your computer and use it in GitHub Desktop.
Save raorao/9594552 to your computer and use it in GitHub Desktop.

Sampler

The challenge is to implement a program called "sample" that outputs a sorted list of random numbers to the console. Your program should be run like this:

ruby sample MEMBERS LIMIT

MEMBERS is the number of results you want the program to output, and LIMIT is the upper limit for the sample range. All results should be greater than or equal to 0 and less than LIMIT. Some examples:

$ ruby sample.rb 3 10
0
1
5

$ ruby sample.rb 3 10
1
2
9

$ ruby sample.rb 20 400
1
3
4
25
32
36
42
56
93
111
137
139
153
213
222
226
263
289
293
314

Once you've got a solution working, try it on larger numbers, like this:

$ ruby sample.rb 5000000 1000000000

A good solution will take around 3 minutes to finish in that situation. A great solution will take around a minute to complete. And if it finishes under 30 seconds, I don't believe you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment