I think you can guarantee that the picked list would:
- Provide the fullest possible coverage of numbers
- Skip at least fully superfluous lists
And do it in O(2n) where n is list count (assuming lists are of similar length).
Before anything, zero-init a list for each number (called a number list). You'll need to do two passes over your lists.
On a first pass, check each list value against your number list. If at least one corresponding value in a number list is a zero (meaning our current list has a number we did not encounter before), add the list to the result and increment each position in a number list that is present in a current list by 1.
In our case:
Numbers: 0, 0, 0, 0, 0, 0, 0, 0, 0
List(1)="3,5,6,7,9"
As Numbers(3)==0, we add List(1) to the output and modify Numbers:
Numbers: 0, 0, 1, 0, 1, 1, 1, 0, 1
In a similar vein, we iterate all our lists (and add all of them, actually); our Numbers after the first pass should look like this:
Numbers: 1, 2, 1, 2, 2, 3, 2, 2, 4
Lists: 1, 2, 3, 4, 5
Now do a second pass, only over lists added on a first pass. If every element in a list has a value >1 in a number list, remove the list and decrease the corresponding number list by 1.
List(1)="3,5,6,7,9"
Numbers: 1, 2, 1, 2, 2, 3, 2, 2, 4
Numbers(3)==1, so this list remains.
List(2)="1,2,6,9"
Numbers(1)==1, so this list remains.
List(3)="5,8,9"
Numbers(5)==2>1, Numbers(8)==2>1, Numbers(5)==4>1, so we are removing this list, new numbers:
Numbers: 1, 2, 1, 2, 1, 3, 2, 1, 3
List(4)="2,4,6,8"
Numbers(8)==1, so this list remains.
List(5)="4,7,9"
Numbers(4)==2>1, Numbers(7)==2>1, Numbers(9)==3>1, so we are removing this list, new numbers:
Numbers: 1, 2, 1, 1, 1, 3, 1, 1, 2
Lists: 1, 2, 4
This, however, does not guarantee that it's a minimum amount of lists, but entirely superfluous lists would be removed, and all possible numbers would be present (have at least one reference in a number list).
Another way I thought it could be resolved is by transposing the lists into numbers like this:
Number(1)=$lb(2)
Number(2)=$lb(2, 4)
Number(3)=$lb(1)
Number(4)=$lb(4, 5)
Number(5)=$lb(1, 3)
Number(6)=$lb(1, 2, 4)
Number(7)=$lb(1, 5)
Number(8)=$lb(3, 4)
Number(9)=$lb(1, 2, 3, 5)
After that is done, any number with just one reference must be picked (meaning it's present in only one list). In our case, numbers 1 and 3, resulting in picking lists 2 and 1.
All numbers in lists 1 and 2 must also be picked: 1, 2, 3, 5, 6, 7, 9
Next, we delete Numbers that we already picked, leaving us with:
Number(4)=$lb(4, 5)
Number(8)=$lb(3, 4)
From the remaining Numbers, we need to remove lists that we already picked (so 1 and 2), but in your example, they are not present anyway.
However, after this cleanup, we might encounter a situation where a number is present in only one list. In that case, the first step needs to be redone again until we arrive at a situation where no number is present only in one list, so in our case:
Number(4)=$lb(4, 5)
Number(8)=$lb(3, 4)
After that, pick a list with the largest amount of different numbers - 4 in our case and repeat from the beginning. Eventually, you'll arrive at empty Numbers local, meaning the task is complete.
Inherit from %JSON.Adapter?







Any valid alphanumeric section name will work. For example:
Class Utils.BO Extends Ens.BusinessOperation { Property MySetting; Parameter SETTINGS = "MySetting:My Custom Category"; }
Will create a new
My Custom Category
for this business host:Settings names can be localized by following this guide (categories too probably, but I haven't tried). Domain would be
Ensemble
.