Ruby Quiz 39
Here is my solution to Ruby Quiz 39: Sampling. This solution, which takes roughly 1.75 minutes to run realtime (0.010 sec user time) is so short, I present it here in its entirety:
This solution is completely out-of-the-box. I played with a few
optimizations, without looking for this algorithm anywhere online. Instead
of using a Set
(which is backed by a Hash
), I wanted to create a
range
-length array and mark each selected value using that array. With a
range of 10e9, my machine ran out of memory.
Disk I/O took about 45 seconds of the total time. There’s probably a way to speed that up.
Back to my Ruby Quiz solutions page.