C# algorithm for figuring out different possible combinations...

Posted by ttomsen on Stack Overflow See other posts from Stack Overflow or by ttomsen
Published on 2010-04-22T23:15:50Z Indexed on 2010/04/22 23:23 UTC
Read the original article Hit count: 258

Filed under:
|
|

I have 10 boxes, each box can hold one item from a group/type of items, each 'group' type only fits in one of the 10 box types. The pool can have n number of items. The groups have completely distinct items. Each item has a price, i want an algorithm that will generate all the different possibilities, so i can figure out different price points.

so a smaller picture of the problem

BOX A - can have item 1,2,3,4 in it

BOX B - can have item 6,7,8,9,10,11,12

BOX C - can have item 13,15,16,20,21

The items are stored in a db, they have a column which denotes which box they can go in. All box types are stored in an array, and I can put the items in a generic list. Anyone see a straightforward way to do this.

I have tried doing 10 nested foreach's to see if i could find a simpler way. The nested loops will take MANY hours to run. the nested for each's basically pull all combinations, then calculate a rank for each combination, and store the top 10 ranked combination of items for output

© Stack Overflow or respective owner

Related posts about c#

Related posts about algorithm