Constraint elements in a 2D array to a particular number a particular number of times

I created a mew topic as asked.