SeedRandom[1];
n = 2;
plist = RandomSample[IntegerPartitions[37, {6, 7}], 200];
The list is still too large; let's reduce it to 20 entries for better visualization.
xlist = plist[[1 ;; 20]]
For n=2, four repetitions of an element are not allowed. The entries underlined in red should be deleted.
For n=3, five repetitions of an element are not allowed. The entries enclosed by the green box should be deleted.
pos = First /@
Position[Tally /@ xlist, {_, x_ /; x > n + 1}, Infinity,
Heads -> False]
{1, 6, 13, 16, 17, 19}
Delete[xlist, List /@ pos]
{{23, 4, 4, 3, 2, 1}, {21, 5, 4, 4, 2, 1}, {15, 11, 5, 4, 1, 1}, {12,
7, 6, 4, 4, 2, 2}, {10, 9, 9, 7, 1, 1}, {14, 5, 4, 4, 4, 3, 3}, {13,
11, 5, 4, 2, 1, 1}, {14, 10, 4, 4, 4, 1}, {17, 6, 4, 4, 3, 2,
1}, {16, 5, 5, 5, 4, 1, 1}, {9, 9, 5, 5, 4, 3, 2}, {14, 12, 3, 3, 2,
2, 1}, {21, 9, 2, 2, 2, 1}, {12, 10, 9, 2, 2, 2}}
Now you can turn it into a function with n
as a parameter if you wish to. IntegerPartitions
grow in size rapidly so an attempt to make tuples of two large sets may run into difficulties. I hope this gives you a pointer in the right direction.
DeleteCases
? $\endgroup$