First you will have to group the instances, and the best method to do that is with an instance variable.
You will then have to do a loop of all the groups.
That is.... unless you go at it from the front end, or creation, where for each group you give the head a variable with the count of instances in its group, and so long as that variable is less than x amount the group may add a new instance.
That would probably be better than the culling method.