mardi 23 décembre 2014

Randomly break up array into chunks of at least 3 with even distribution

I have an array of size n, and would like to break it up into m chunks of size at least 3. For example, given the array



[1,2,3,4,5,6,7,8,9,10]


and m=3, we could break the it up into



a=[1,2,3,4][5,6,7][8,9,10]
b=[1,2,3][4,5,6,7][8,9,10]
c=[1,2,3][4,5,6][7,8,9,10]


We could think of these solutions as being represented by the pairs (4,3,3) (3,4,3) and (3,3,4). I would like a function that given an array, n, and m, returns a random solution AND returns these solutions with an even distribution (so that you are no more likely to get one particular solution than any other). (This function needs to work for n=50, so for performance reasons we cannot do this by calculating all possible solutions.)





Aucun commentaire:

Enregistrer un commentaire