This is probably a question very similar to other ones asked previously, but I can't find the solution to my specific case.
I have lists of items. EDIT I'll show 4 lists, but the real problem could have thousands of lists, say 3000:
List 1: Items A, B, C, D
List 2: Items C, D, E, F
List 3: items A, D, F
List 4: Items B, C, D, F
I want to group the lists so that the resulting groups have the minimum sum of unique items.
Example:
List (1 + 2): A, B, C, D, E, F = 6 items
List (3 + 4): A, B, C, D, F = 5 items
Total = 6 + 5 = 11 items
Alternative solution
List (1 + 4): A, B, C, D, F = 5 items
List (2 + 3): A, C, D, E, F = 5 items
Total: 5 + 5 = 10 items, which would be a better solution than the first one. EDIT The number of groups should be editable in the code/by user input and it can range from 1 to 10.
The purpose is to create scenarios:
- 1 group --> all the 3.000 lists are merged together, the result is a simple count of unique items
- 2 groups --> 1.500 lists per group (approximately, it doesn't have to be exact), the purpose is to find the smart grouping to minimize the sum of unique items of the 2 groups
- 3 groups --> ...
- 4 groups --> ...
- 3.000 groups --> each list is a group, where the result is the sum of the distint count of items in each list
Thank you very much.