Given a large set of unsorted lego pieces, and a list of possible lego sets with associated dollars values:
Do a single pass to identify/scan all the pieces. Then based on that, divide those into sets such that the associated dollar values are maximized and such that the number of sets is minimized.
Then select the 11 most valuable of the sets and use the sorting machine to sort these out, all the remaining legos go in the 12 set. Repeat.
Simple ;D
The workflow would be: sort about 10% of the pieces in a test, use that to determine which sets are present based on the rare pieces, then pull those out of the bulk in one pass, it can do 12 sets in one go. Then you do it all over again until there is no more left.