The thing I need to do is very simple, so I don’t need to create a complex program and I only need to use this once, making the result of this the feed data for the real project I’m working now.
I need to obtain the 50 first (or, better, 50 randoms) combinations of a set of N elements, being N every value from 2 to 50.
In Ruby, logically, will be something like
require 'pp'
pp (1..50).to_a.permutation.to_a.first(50)
But sadly, that programs always ran out of memory. As I matter of fact, the “maximum” number I could generate on my machine is 10, and I need 50.
I’m pretty sure that exists some other, more efficient way, to achieve this, but because I don’t know very well the maths involved, I need to desperately ask for you help. Any of you know about some gem, library, or even an algorithm who do that in a way that doesn’t consume all the memory. It doesn’t matter if is slow, as I said, I only need to generate this thing once.
Don’t call
to_aon the permutation enumerator, just use it as an enumerator:But if you want random permutations, you can just shuffle the array 50 times: